I try to raise more than one exception in an if-else branch: The code is the following:
x = input()
try:
if int(x) < 0: # the number should not be a negative number
raise("This is a negative number.")
if int(x) >= 4:
print("That a lot.")
else:
print("That is not so much.")
except ValueError: # the input should be a other than a number
print("You did not entered a number.")
The following error message occurs: TypeError: exceptions must derive from BaseException
Aucun commentaire:
Enregistrer un commentaire