有人可以让我知道为什么会有SyntaxError
吗?我使用macOS Mojave,并安装了IDLE
版本3.7.1。
if name == 'Alice':
print('Hi, Alice.')
elif age < 12:
print('You are not Alice, kiddo.')
elif age > 2000:
print('Unlike you, Alice is not undead, immortal vampire.')
elif age > 100:
print('You are not Alice, grannie.')
答案 0 :(得分:3)
缩进是错误的:
name = input('whats your name? ')
age = int(input('whats your age? '))
if name == 'Alice':
print('Hi, Alice.')
elif age < 12:
print('You are not Alice, kiddo.')
elif age > 2000:
print('Unlike you, Alice is not undead, immortal vampire.')
elif age > 100:
print('You are not Alice, grannie.')
答案 1 :(得分:0)
'elif'应该与'if'具有相同的缩进量
删除精灵之前的空白
if test expression:
Body of if
elif test expression:
Body of elif
else:
Body of else