I am currently creating a program which will ask the user to enter a year and then states whether it is a leap year or not by seeing if the year is divisible by 4. It also has a type check, presence check and a length check. I keep on getting the AttributeError: 'int' object has no attribute 'isnumeric'
All in all, the program works well as I want it to (code below) but when the program has finished it states the aforementioned attribute error. Why does it display that message and how can I solve it?
Code:
print("Did you know that the last leap year was in 2020?")
print("To find out if a year is a leap year, use this program")
year = input("Please enter a year\n")
year = str(year)
valid = False
while valid == False:
if year == "":
print("Error. Please enter a year - it should be 4 digits long.")
year = input("Please enter a year\n")
year = year.decode(year)
valid == False
else:
if year.isnumeric() == False:
print("Error. Please enter a year - it should be 4 digits long.")
year = input("Please enter a year\n")
year = str(year)
valid == False
else:
if len(year) != 4:
print("Error. Please enter a year - it should be 4 digits long.")
year = input("Please enter a year\n")
year = str(year)
valid == False
else:
year = int(year)
rem = year%4
if rem == 0:
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year, unfortunately")
valid == True