vendredi 13 juillet 2018

If, Elif and Else in Python Not working

I am trying to use if statements in Python to calculate the weight from the physics equation weight = mass * acceleration. The acceleration is different dependent on latitude. At 45 degrees and above acceleration is 9.82 and at below 45 degrees acceleration is 9.79. When calculating the weight I am asking the user for the latitude using the input box and then using an if statement to determine which acceleration should be used in the calculation. For some reason my if and elif and else statement isn't working and outputs the same answer for weight no matter the latitude:

mass = 44 
acceleration1 = 9
acceleration2 = 9.82

latitude = input("What is the latitude")

if latitude >= 45:
 weight = mass * acceleration2
print weight 
else:
 weight = mass * acceleration1 
 print weight

The answer keeps coming out as 432.08 even if I have a latitude of below 45. Can someone advise what I am doing wrong here?

Aucun commentaire:

Enregistrer un commentaire