简体   繁体   中英

Syntax Error on the Python if statement

Data = 80
età = input('Per iniziare dimmi quanti anni hai:')
Data = Data - età
fumo = eval(input('Fumi? (si/no)')
 if fumo == 'si':
    Data = Data - 10
 else:
    pass
print('Ti restano da vivere ' Data 'anni')

I can't get where the error is, every time i run this i get syntax error on the colon at the end of the "if" line I've red every post on the if else elif statements in python but still can't get why.

fumo = eval(input('Fumi? (si/no)')

Right there. You're missing a parenthesis at the end of this line. The open parenthesis makes Python think your if statement is actually part of this statement.

You're missing a parenthesis at the end of your fumo = eval(input('Fumi? (si/no)') line.

Also, do not indent your is/else block.

Data = 80
età = input('Per iniziare dimmi quanti anni hai:')
Data = Data - età
fumo = eval(input('Fumi? (si/no)'))
if fumo == 'si':
    Data = Data - 10
else:
    pass
print('Ti restano da vivere', Data, 'anni')

EDIT:

I've also modified your printing line. You need to either separate each part that you want to print with commas, or concatenate them like so:

print('Ti restano da vivere ' + str(Data) + ' anni')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM