98.0k views
2 votes
In python

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 Ayrosa
by
7.1k points

1 Answer

4 votes

Answer:

year = 1776

if year >= 2101:

print("Distant future")

elif year >= 2001:

print("20th century")

else:

print("Long ago")

Step-by-step explanation:

Alternatively, if you wanted the user to assign a value to the "year" variable. You could replace year = 1776 with year = int(input("Enter a year: "))

User Theadam
by
8.1k points