注册 登录
编程论坛 Python论坛

Python if 语法

mb19881022 发布于 2012-03-25 22:48, 889 次点击
score=70
>>> if score>60
SyntaxError: invalid syntax
>>> if score>60:
    print("jige")
    else:
        
SyntaxError: unindent does not match any outer indentation level
>>> print(score)
70
>>> if score>60:
    print("jige")
    elif(score<60)
   
SyntaxError: unindent does not match any outer indentation level
>>> if score>60:
    print("jige")
    else:
        
SyntaxError: invalid syntax
>>> if score>60:
    print("jige")
    else:
        
SyntaxError: unindent does not match any outer indentation level
真的搞不懂为什么会出错,照着手册来学习的啊?
3 回复
#2
robey2012-03-27 13:16
程序代码:
>>> score=70
>>> if score>60:
    print ("jige")
else:
    print ("robey")

jige
>>>
解释:
else:  -->需要顶行写

if score>60:
    print ("Jige")
else:
    print ("robey")

你是被">>>"干扰了。if 是从>>>后面顶行写。紧跟的else也要保持顶行,你把">>>"去掉就是上面这个样子了。

[ 本帖最后由 robey 于 2012-3-27 13:20 编辑 ]
#3
快乐出发02202012-04-30 00:31
要注意代码的缩进啊
#4
楼兰后主2012-06-19 13:21
呵呵,楼主直接在编译界面敲入代码的,我认为刚开始学习,最好打开一个编辑窗口,敲完代码,直接F5运行。楼上说的代码缩进很对。
1