jeudi 24 décembre 2020

Why it appears an error even if I have a try and except?

def temperature_def(tem):       
try:
    if tem >= 34 and tem <= 38:
        return tem
    else:
        print("You can not enter the list!")
        quit()
except:
    print("Enter a number!")
    quit()

pearson1 = People_class((input("Name and Surname (with out accents): ").lower()), int(input("Age: ")),
        covid_status_def(input("Someone close to you either has covid or had it? ").lower().strip()),
                    temperature_def(float(input("What is your temperature in degrees? "))))

Here im trying to get a number for the if statement, I am taking the input in the last line.

The try and except should recognise if a number is not inputted (no idea if that is a word), and should do as it follows, but, when I type something that is not a number, it appears the error.

To clarify im doing a list and the "float(input(..." can not be moved (as far as I know).

Thanks in advance and happy holidays :D

Aucun commentaire:

Enregistrer un commentaire