简体   繁体   English

Python if语句的语法错误

[英]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. 我无法得到错误的位置,每次运行时,我都会在“ if”行末尾的冒号上出现语法错误,我在python中的if else elif语句上的每个帖子都变红了,但仍然无法明白为什么。

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. 开放的括号使Python认为您的if语句实际上是该语句的一部分。

You're missing a parenthesis at the end of your fumo = eval(input('Fumi? (si/no)') line. 您在fumo = eval(input('Fumi? (si/no)')行的末尾缺少括号。

Also, do not indent your is/else block. 另外,请勿缩进您的is / else块。

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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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