0

I need to restrict this loop from using values greater than 101 and less than zero. The assignment is to make program that finds the average of test scores inputed. I can't figure out what to do, but i feel it's simple. thanks in advance

T = 0

GC = 0
grade = int(input("Enter a grade, 999 to stop: "))


while grade != 999:

    if grade < 0:
        int(input('Enter a grade that is greater than zero: '))
    elif grade > 101:
        int(input('Enter a grade that is less than 102: '))
    else:
        T = T + grade
        GC = GC + 1
        grade = int(input("Another grade: "))

if GC != 0:
    average = round(float(T)/GC,2)
    print("The number of scores:",  GC,'\n',
          'The average is', average)
2
Contributors
2
Replies
21
Views
4 Years
Discussion Span
Last Post by hmx7
0

999 can't stop your program because of

elif grade > 101:

Try using (but it still errors if a non-number/letter is entered)

grade = -1
while grade != 999:
    grade = int(input('Enter a grade that is greater than zero: '))
    if 0 <= grade < 101: 
        ## do calcs for a correct entry
    else:
        print "incorrect entry"

Edited by woooee

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.