Hi, im trying to find a way to repeat this code with out losing the count of 1,2,3 and 4, when the user enters a number different from 1,2,3 or 4. Because in line 26 I call for main() again but when I do that it loses count of everything.
def main():
print "WELCOME TO THE GRADE LEVEL CALCULATOR!"
print
x = 0
f = 0.0
s = 0.0
j = 0.0
se = 0.0
nstudents = 0
while x <= 4:
print "Please choose the class standing from the following menu:"
print " 1) Freshman"
print " 2) Sophomore"
print " 3) Junior"
print " 4) Senior"
print " 5) Quit"
print
x = input("Please enter your choice here: ")
if x > 5 or x < 1:
print "Invalid choice. Must choose 1 - 5."
main()
print
elif x == 1:
f = f + 1
nstudents = nstudents + 1
elif x == 2:
s = s + 1
nstudents = nstudents + 1
elif x == 3:
j = j + 1
nstudents = nstudents + 1
elif x == 4:
se = se + 1
nstudents = nstudents + 1
elif x == 5:
print "Total number of students entered: ", nstudents
total = f + s + j + se
fper = (f / total ) * 100
sper = (s / total ) * 100
jper = (j / total ) * 100
seper = (se / total ) * 100
print "Freshman: ", fper,"%"
print "Sophomores: ", sper,"%"
print "Juniors: ", jper,"%"
print "Seniors: ", seper,"%"
main()