Home > Software engineering >  How do you continue to ask for integers and add them in a loop?
How do you continue to ask for integers and add them in a loop?

Time:10-26

for i in range(assignment_quantity):
    assignment_grade = int(input("What was your grade on assignment#"   str(i)   ":"))
    print(assignment_grade)
    total_assignment_grade = assignment_grade
    complete = total_assignment_grade   assignment_grade
    print(complete)

The user is supposed to continue entering numbers and the code is supposed to add the numbers before adding more numbers the user input; I am extremely stuck on this.

CodePudding user response:

You are overriding total_assignment_grade each round so complete is just 2x what ever you gave as input. You need to add to complete what ever was given as input:

assignment_quantity = 3

complete = 0

for i in range(assignment_quantity):
    assignment_grade = int(input("What was your grade on assignment#"   str(i)   ":"))
    print(assignment_grade)
    complete  = assignment_grade
    print(complete)

  • Related