开发者

While function python

Hello is use eclipse and pydev, I was wondering why my sample code won't work trying to use the while function.

print("Welcome to the annoying program")
response = ""
while response != "Because.":
  response = input("why\n")

print("Oh,ok")

the output is the following:

Welcome to the annoying program
why
Because.
Traceback (most recent call last):
 File "/Users/calebmatthias/Document/workspace/de.vogella.python.first/simpprogram.py", l      ine 9, in <module>
   response = input("why\n")
File "/Users/calebmatthias/Desktop/eclipse     2/plugins/org开发者_JAVA百科.python.pydev_2.2.3.2011100616/PySrc/pydev_sitecustomize/sitecustomize.py", line 210, in input
return eval(raw_input(prompt))
File "<string>", line 1
Because.
       ^
SyntaxError: unexpected EOF while parsing


The input function in 2.x evaluates the input as Python code! Use the raw_input function instead.

With input, your text "Because." is being evaluated, and it's a syntax error because the dot isn't followed by anything.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜