【发布时间】:2017-10-17 19:56:55
【问题描述】:
username = "chicken"
password = "monkeys"
print("Welcome to example")
answer1 = input ("Do you have an example account(Please type yes or no)?")
if answer1 == "yes":
username == input("please input username")
password == input("Please input your password")
while username and password == True:
print("access granted")
while username or password == False:
print("access denied")
此代码正在运行,但它一直说访问权限不断被授予
【问题讨论】:
-
这段代码有很多错误,我什至不知道从哪里开始。
-
(1) 布尔表达式的评估方式与您的大脑评估英语语法的方式不同。
username and password == True按字面意思计算为username and (password == True)而不是(username == True) and (password == True)。 (2) 您需要使用=而不是==来分配变量值。 (3) Indentation matters in Python. -
您的脚本中有几个错误。你能告诉我,你在哪里检查用户名密码组合是否有效?
标签: python while-loop passwords