- #1
acurate
- 17
- 1
Homework Statement
I need a program where the program needs to ask me a name of a student and then a grade.
1) The program needs to end if a 0 is entered.
2) If the name has a number in it, the program should ask the user to enter another name.
3) After the name is correctly entered the program needs to ask to enter the student's grade
4) Student's grade cannot be higher than 10 but no less than 2.
5) Also the program should end if a 0 is entered in the grade area
Homework Equations
The Attempt at a Solution
This is what I've done:
Code:
while True:
name = input ("Enter a student's name: ")
if name.isalpha():
continue
elif name == "0":
name = input ("A zero is entered. Session cancelled.")
break
else:
while not name.isalpha():
name = input ("Error. Enter a student's name again: ")
How do I make the program ask for the student's grade AFTER the grade is entered correctly?
Because what I have now it only asks me to enter a grade ONLY AFTER the grade is entered incorrectly and entered again.
How can I get the program to ask the grade right after the name is entered correctly after the first try?
I'm sure there is something wrong with the continue's and break's but I cannot tell what.
Should I continue like this:
Code:
while True:
name = input ("Enter a student's name: ")
if name.isalpha():
continue
elif name == "0":
name = input ("A zero is entered. Session cancelled.")
break
else:
while not name.isalpha():
name = input ("Error. Enter a student's name again: ")
while True:
grade = input ("Enter a student's grade: ")
if grade >= 10:
continue
elif grade == "0":
grade: input ("A zero is entered. Session cancelled.")
break
else:
while not grade ?