mingloveqing 发表于 2010-7-9 08:52

Python shell 错误

小弟是一个初学者,搞了很久都没在Pythonshell里面循环成功,请各位大侠指点,谢谢:
一下是我在PythonShell里面写的代码,最后就出现了一个错误了,
a,b=0,1
while b < 100:
...    print b,
SyntaxError: expected an indented block (<pyshell#18>, line 2)


外部三电铃 发表于 2010-7-9 09:09

你所用Python的版本,如果是3.0以上得用[color=#ff0000][b]print(b)[/b][/color]

lampeter123 发表于 2010-7-9 11:13

你的程序死循环了

mingloveqing 发表于 2010-7-9 17:59

>>> a,b=0,1
>>> while b<100:
    print (b),b=b+1
   
SyntaxError: can't assign to function call (<pyshell#2>, line 2)
如果像这样的话,会出现这个错误了。各位教一下吧。能把程序也贴上来吗?这是小弟开始的第一步,可能也是很关键的一步哦~!谢谢!!

yangfanconan 发表于 2010-7-9 18:18

回复 4楼 mingloveqing

在PY3.0中PRINT是作为一个函数存在的。
>>> print("yang")
yang
>>> a=100
>>> print("",a)
100
>>>

yangfanconan 发表于 2010-7-9 18:20

[quote][b]以下是引用[u]yangfanconan[/u]在2010-7-9 18:18:41的发言:[/b]

在PY3.0中PRINT是作为一个函数存在的。
>>> print("yang")
yang
>>> a=100
>>> print("",a)
100
>>>
[/quote]当然
A=100
print(a)
也是正确的。

yangfanconan 发表于 2010-7-9 18:26

回复 4楼 mingloveqing

[code]a,b=0,1
[color=#0000FF]while[/color] b<100:
    b=b+1
    [color=#0000FF]print[/color](b)[/code]测试通过[tk04]

外部三电铃 发表于 2010-7-9 22:31

可能是tab空格跟普通空格混用了,python的缩进要求统一,要么全用tab要么全用空格

yangfanconan 发表于 2010-7-10 17:45

[tk04]顶 [color=#ccff00]外部三电铃。
我最近总看到,用中文符号写的代码- -
[/color]

vfdff 发表于 2010-8-2 00:50

回复 7楼 yangfanconan

哪里看循环的结束!

yangfanconan 发表于 2010-8-3 06:53

回复 10楼 vfdff

我就是在编译器上测试下代码。

vfdff 发表于 2010-8-22 19:20

弱弱的问下,Python 和 shell不是两种独立的语言吗?

lucky563591 发表于 2010-11-20 09:19

和C++有不同的吗

页: [1]

编程论坛