Skip to main content
 首页 » 编程设计

python之而函数python

2025年05月04日21lhb25

您好,我正在使用 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 

请您参考如下方法:

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

使用 input,您的文本“因为”。正在计算,这是一个语法错误,因为点后面没有任何内容。