Python Forum

Full Version: looping with if/elif
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm not sure why this does not print grade value. I tried moving indent. I am trying to put grade after weighted average.

students = ['Tony','Steve', 'Bruce', 'Natasha', 'Carol', 'Sam']
category = [ 'Assignment', 'Quizzes', 'Projects', 'Essays', 'Exams']
weighted = [.1, .1, .3, .25, .25]

for i in students:
    print(i)
    total = 0

    for num in weighted:

        score = float(input('Enter scores: ')) * num
        total += score
        total /= sum(weighted)
            if total >= 90:
                grade = 'A'
            elif total >= 80:
                grade = 'B'
            elif total >= 70:
                grade = 'B'
            elif total >= 60:
                grade = 'D'
            else:
                grade = 'F'
    print('wieghted average = ' + str(total)
    print()
    print('Letter Grade: ' + grade)
I get this as output.
Tony
Enter scores: 95
Enter scores: 95
Enter scores: 80
Enter scores: 85
Enter scores: 82
wieghted average = 84.75
Steve
Enter scores:
With the code published here you will get error, because indentation of lines 14-23 is wrong. Post the actual code you run.
I made a new file with data but ran old program. here is the actual program where I go indent error.
students = ['Tony',]
category = [ 'Assignment', 'Quizzes', 'Projects', 'Essays', 'Exams']
weighted = [.1, .1, .3, .25, .25]

for i in students:
    print(i)
    total = 0

    for num in weighted:

        score = float(input('Enter scores: ')) * num
        total += score
        total /= sum(weighted)
            if total >= 90:
                print('A')
            elif total >= 80:
                print('B')
            elif total >= 70:
                print('c')
            elif total >= 60:
                print('d')
            else:
                print('f')

    print('wieghted average = ' + str(total)
Error Message:
Error:
File "/Users/c/Downloads/#3.py", line 14 if total >= 90: ^ IndentationError: unexpected indent Process finished with exit code 1
What don't you understand? Why are lines 14-23 indented so much?
If I decrease indent, I get the following parsing error message:
Error:
File "/Users/c/Downloads/#3.py", line 28 ^ SyntaxError: unexpected EOF while parsing Process finished with exit code 1
you have one missing closing parenthesis on last line
students = ['Tony',]
category = [ 'Assignment', 'Quizzes', 'Projects', 'Essays', 'Exams']
weighted = [.1, .1, .3, .25, .25]
 
for i in students:
    print(i)
    total = 0
 
    for num in weighted:
 
        score = float(input('Enter scores: ')) * num
        total += score
total /= sum(weighted)
if total >= 90:
    print('A')
elif total >= 80:
    print('B')
elif total >= 70:
    print('c')
elif total >= 60:
    print('d')
else:
    print('f')

print('wieghted average = ' + str(total))
Thank you.