My current classes and test grades are Science test grades: 97 56 73 90 79 Avera
ID: 3662632 • Letter: M
Question
My current classes and test grades are
Science test grades:
97
56
73
90
79
Average: 79.00 %
How can I print this on one line ?
Math test grades: 89 100 85 94 Average: 92.00 %
My code is:
print("My current classes and test grades are")
#pick a course and its scores, find its average, and print them all
for (course, scores) in grades.items():
counter = 0 #to find no of scores
accumulator = 0 #to find total score
print(course, "test grades:",)
for s in scores:
print(s,)
counter = counter + 1
accumulator = accumulator + s
print("Average:",format(accumulator/counter, '.2f'), "%")
Explanation / Answer
I think you are using pythone 3 thats why print(s,) didn't do the job.
In python 3 try using print(s,end=" ")
so
print("My current classes and test grades are")
#pick a course and its scores, find its average, and print them all
for (course, scores) in grades.items():
counter = 0 #to find no of scores
accumulator = 0 #to find total score
print(course, "test grades:",)
for s in scores:
print(s,end=" ")
counter = counter + 1
accumulator = accumulator + s
print("Average:",format(accumulator/counter, '.2f'), "%")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.