Randall McGrath
Randall McGrath

Reputation: 33

Multi-branch if-else statements in Python

I have been looking forward to learning about If-else statements, but now I've gotten stuck on multi-branch ones by receiving a syntax error, although there may be other issues.

The assignment asks, "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"." if the user inputs 1776 they get long ago and if they put 2200, they also should get "long ago". here is where my code is at so far,

year = int(input())
if year>= 2101:
    print('Distant future')
    elif year>=2001:
    print('21st century')
    elif year>=1901:
    print('20th century')
    else:
        print('Long ago')

I received a syntax error.

Upvotes: 0

Views: 12504

Answers (2)

praneeth REDDY
praneeth REDDY

Reputation: 21

it just an indentation the correct format to write code is

year = int(input())
if year>= 2101:
    print('Distant future')
elif year>=2001:
    print('21st century')
elif year>=1901:
    print('20th century')
else:
    print('Long ago')

Upvotes: 2

Russ J
Russ J

Reputation: 838

Your indentations are WAY off. Python doesn't rely heavily on brackets and such. Instead, spacing, new lines, and indentations are SUPER important.

year = int(input())
if year >= 2101:
    print('Distant future')
elif year >= 2001:
    print('21st century')
elif year >= 1901:
    print('20th century')
else:
    print('Long ago')

Upvotes: 2

Related Questions