否则如果和elif不为我的python cod工作

2024-04-26 02:53:48 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我学习代码的第一天。我试过这个代码,不知道为什么失败了。非常感谢您的帮助:

a=int(input())

if a>10:
    print("your number is greater than 10")
    else:

我得到SyntaxError: invalid syntax


Tags: 代码numberinputyourifiselseint
3条回答
if a>10:
    print("your number is greater than 10") #indent the print statement
else:
    print('Not greater than 10')
    #you need to perform an action inside the else condition

出现缩进错误:

if condition:  
    code...  
elif condition:  
    another code...  
else:  
    last code...  

其中elifelse部分是可选的,elif表示{}。在

PS:使用int(input())否则将得到一个字符串而不是一个int

你的缩进不正确。应该如下所示:

a=input()
if a>10:
    print("your number is greater than 10")
else:
    # You didn't have anything in your else statement so either remove it or add a statement...
    print("your number is <= 10")

参见python documentation on indentation。在

相关问题 更多 >

    热门问题