mardi 22 juin 2021

How do I fix a Floating Point Calculation issue?

So, last week, I got some work sent to me for Python 3, and one of the questions goes as follows: "Write (a) program which inputs the year. Your program should output whether it is a leap year or not. To work out if it is a leap year, test whether it is exactly divisible by 4."

This is what I've got so far:

yearStr = input("Please input a year: ")
year = float(yearStr)

calculation = year / 4

print(calculation)

if calculation == .0:
    print("This is a leap year.")
else:
    print("This is not a leap year.")

When I run the program, the IF statement doesn't work as intended. Could you help me, please?

Aucun commentaire:

Enregistrer un commentaire