Skip to main content
 首页 » 编程设计

python input() 没有按预期工作

2025年05月04日8yjmyzz

<分区>

我是一个 python 新手。我正在熟悉循环并尝试了书中的这个例子

while True: 
        s = input('Enter something : ') 
        if s == 'quit': 
                break 
        print('Length of the string is', len(s)) 
print('Done') 

但是输出如下

Enter something : ljsdf 
Traceback (most recent call last): 
  File "trial_2.py", line 2, in <module> 
    s = input('Enter something : ') 
  File "<string>", line 1, in <module> 
NameError: name 'ljsdf' is not defined