[Tutor] Printing a list count - Help
Derek Jenkins
derektjenkins at gmail.com
Fri Aug 29 21:49:11 CEST 2014
honor_roll_count = 0
student_grades = ["A", "C", "B", "B", "C", "A", "F", "B", "B", "B", "C", "A"]
for grades in student_grades:
if grades == "A" or grades == "B":
honor_roll_count = honor_roll_count + 1
print honor_roll_count
That works more to my liking. Thanks a million, Danny and Bob!
On Fri, Aug 29, 2014 at 3:42 PM, boB Stepp <robertvstepp at gmail.com> wrote:
> On Fri, Aug 29, 2014 at 2:17 PM, Derek Jenkins <derektjenkins at gmail.com> wrote:
>> Hi everybody,
>>
>> I have a list that I want to go through and finally print a total
>> count of particular items. In this case, I want to print the result of
>> how many A's and B's are in the list.
>>
>> honor_roll_count = 0
>> student_grades = ["A", "C", "B", "B", "C", "A", "F", "B", "B", "B", "C", "A"]
>>
>> for grades in student_grades:
>> honor_roll_count = honor_roll_count + 1
>> if grades == "A" or grades == "B":
>> print honor_roll_count
>>
>
> Are you sure you have your increment of honor_roll_count where you
> want it? As it is placed you are counting how many grades of any kind
> there are.
>
> --
> boB
More information about the Tutor
mailing list