I want to make the loop continue and catch errors like entering "bob" as an input or integers less than 1 and greater than 4.
salesNum = input("How many sales persons to process? ")
for num in salesNum:
salesName = input("Enter Salesperson Name: ")
salesLevel = 0
while salesLevel == 0:
try:
salesLevel = int(input("Enter Salesperson Level: "))
if salesLevel < 1 or salesLevel > 4:
print("error, try again.")
salesLevel = int(input("Enter Salesperson Level: "))
except ValueError:
print("error, try again")
continue
hoursWorked = float(input("Enter Hours Worked: "))
salesAmount = float(input("Enter Number of Sales: "))
print("Clear")
It works fine if I make one error, but multiple errors don't get caught and the program moves on to the next questions. I have tried breaking the if statement up, but that doesn't solve the issue.
Aucun commentaire:
Enregistrer un commentaire