为什么我的程序说里根没有被定义,即使我把名字用双引号引起来,我的意思是它不是一个变量?

2024-04-23 21:16:09 发布

您现在位置:Python中文网/ 问答频道 /正文

print ("This is a simple login")
while True:
    enter = input("Enter the password for this computer: ")
    if enter == "Reagan":
        time.sleep(1)
        print ("Your Login is successful")
    else:
        print ("Password didn't match! ")

更新

这是从终端运行时程序的输出:

C:\Python27\python.exe "C:/Python Programming/Practice/for loops.py"        
This is a simple login Enter 
the password for this computer: Reagan 
Traceback (most recent call last): File "C:/Python Programming/Practice/for loops.py", 
line 3, in <module> enter = input("Enter the password for this computer: ") File "<string>",
line 1, in <module> NameError: name 'Reagan' is not defined Process finished with exit code 1

Tags: theforinputisloginpasswordthissimple
1条回答
网友
1楼 · 发布于 2024-04-23 21:16:09

你需要raw_input()

import time
print ("This is a simple login")
while True:
    enter = raw_input("Enter the password for this computer: ")
    if enter == "Reagan":
        time.sleep(1)
        print ("Your Login is successful")
    else:
        print ("Password didn't match! ")

相关问题 更多 >