I'm doing a small program that has the job of a school's subjects and marks management.
HOW IT WORKS
I've created 4 variables: a dictionary, an initialized empty string(for subjects) and two initialized empty integers(one for the marks, the other one for the subjects number). The program asks the user to input the numbers of subjects to work with. After that, it enters in a for loop that repeats itself in the range of the subjects number. And it works fine. Now the problem comes when the user inputs a mark over the range specified. Let's suppose we have a school and the marks we can input are between 1 and 10. The user can't write 11,12 and so on..
CODE
pagella = {}
materia = ""
voti = 0
length = 0
print("Insert the number of subjects, the subjects and the marks-")
num = int(input("Number of subjects: "))
length = len(pagella)
length = num
for i in range(length):
materia = input("Subject: ")
voto = eval(input("Mark: "))
if(voto > 10):
print("Number between 1 and 10")
else:
pagella[materia] = voto
print(pagella)
As you can see, there's the for loop that asks the user to input the subjects and the marks in the range of num(the number of subjects). If I try to input 12 on a mark, the program tells me to input a mark between 1 and 10 so it repeat again the cycle from the beginning. But the problem is that in this case, if I want to have 3 subjects with 3 marks (that means 3 iterations), one is lost because of the wrong mark, so I will not have 3 subjects and marks to input correctly, but only 2.
I hope I've explained correctly everything and someone can help me!
Thanks in advice