while 函数 python

发布于 2024-12-09 16:41:46 字数 758 浏览 0 评论 0原文

你好,使用 eclipse 和 pydev,我想知道为什么我的示例代码无法尝试使用 while 函数。

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

print("Oh,ok")

输出如下:

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.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

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.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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺渁∝ 2024-12-16 16:41:46

2.x 中的 input 函数将输入计算为 Python 代码!请改用 raw_input 函数。

使用输入,输入“因为”文本。正在计算,这是一个语法错误,因为点后面没有跟任何东西。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文