Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use python3 You are tasked with writing the input validation component of a hist

ID: 3757389 • Letter: U

Question

Use python3

You are tasked with writing the input validation component of a historical database. You enter a year into this database, and it should bring up a bunch of facts about that year. However, only certain years can be looked up. That’s where you come in!

The program must re-prompt the user until they provide a year that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., year is odd, and it’s bad year), the program must print out all of the things that are wrong, and how to fix them.

The program follows these rules for years:

1. The year must be after 1800.

2. The year must be before 2000.

3. The year must be even.

4. The year must not be a “bad year” a. Bad years include: 1812, 1863, 1918, 1929, 1932, 1939, 1941, 1963, 1968, 1979

For this part of the homework, you must have an in-line comment at the top of each of your program’s individual if, elif, and else statements, explaining what is being checked by that conditional. (HINT: Think carefully about what your conditionals should look like. If necessary, draw a truth table to help figure out what different inputs will do. Using a Boolean flag will also likely make this easier.)

Explanation / Answer

Screenshot

----------------------------------------------

Program

#User prompt to enter year
year=int(input("Enter year: "))
#Condition to check the error of the year and prompt again
while(year<=1800 or year>=2000 or (year%2)!=0 or year==1812 or year==1863 or year==1918 or year==1929 or year==1932 or year==1939 or year==1941 or year==1963 or year==1968 or year==1979):
   #check less than year and odd year
   if(year<=1800 and (year%2)!=0):
       print("The year must be after 1800,and the year is odd,it should be even ")
   #Check year less than range
   elif(year<=1800):
       print("The year must be after 1800")
   #Check year greater than range and odd
   elif(year>=2000 and (year%2)!=0):
       print("The year must be before 2000,and the year is odd,it should be even ")
   #Check year greater than range
   elif(year>=2000):
       print("The year must be before 2000")
   #Odd year and bad year check
   elif((year%2)!=0 and (year==1812 or year==1863 or year==1918 or year==1929 or year==1932 or year==1939 or year==1941 or year==1963 or year==1968 or year==1979)):
       print("The year is odd,it should be even and It’s bad year(bad years are 1812,1863,1918,1929,1932,1941,1963,1968 and 1979)")
   #Odd year check
   elif((year%2)!=0):
       print("The year is odd,it should be even")
   #Bad year check
   elif(year==1812 or year==1863 or year==1918 or year==1929 or year==1932 or year==1939 or year==1941 or year==1963 or year==1968 or year==1979):
       print("It’s bad year(bad years are 1812,1863,1918,1929,1932,1941,1963,1968 and 1979)")
   #Prompt again
   year=int(input("Enter year: "))
#Otherwise correct
print("You entered correct year")

--------------------------------------------------

Output

Enter year: 1790
The year must be after 1800
Enter year: 2002
The year must be before 2000
Enter year: 1781
The year must be after 1800,and the year is odd,it should be even
Enter year: 2005
The year must be before 2000,and the year is odd,it should be even
Enter year: 1813
The year is odd,it should be even
Enter year: 1812
It’s bad year(bad years are 1812,1863,1918,1929,1932,1941,1963,1968 and 1979)
Enter year: 1879
The year is odd,it should be even
Enter year: 1963
The year is odd,it should be even and It’s bad year(bad years are 1812,1863,1918,1929,1932,1941,1963,1968 and 1979)
Enter year: 1964
You entered correct year
Press any key to continue . . .