126k views
4 votes
Write an if-else statement with multiple branches. If year is 2101 or later, print "Distant future" (without quotes). Otherwise, if year is 2001 or greater, print "21st century". Otherwise, if year is 1901 or greater, print "20th century". Else (1900 or earlier), print "Long ago". Sample output with input: 1776 Long ago

User Tolotra
by
5.3k points

1 Answer

0 votes

Answer:

year = int(input("Enter a year: "))

if year >= 2101:

print("Distant future")

elif year >= 2001:

print("21st century")

elif year >= 1901:

print("20th century")

else:

print("Long ago")

Step-by-step explanation:

*The code is in Python.

Ask the user to enter a year

Use if-else statement to check the year and print the appropriate message given for each condition. If year is greater than or equal to 2101, print "Distant future". If year is greater than or equal to 2001, print "21st century". If year is greater than or equal to 1901, print "20th century". Otherwise, print "Long ago".

User Dan Milburn
by
5.3k points