【问题标题】:'If' loop' with and doesn't print message when inputs conditions are True当输入条件为真时,'If'循环'和不打印消息
【发布时间】:2020-06-14 11:38:54
【问题描述】:

我正在尝试编写一个迷你代码来检查用户/键输入是否正确,代码是下一个:

if emailstatus == True and email in UserKeys == True and UserKeys [email] == key :

  print ('Checked,  you can log in ')    

else:

  print ('wrong email or password, you can not log in')
'''

当我输入正确的电子邮件和密码时,我仍然无法登录(这会生成三个 True 值

我已修复此问题,将“()”添加到 用户密钥中的电子邮件 )中的 if 条件 == True

但我还是不明白这个错误背后的逻辑

pd:完整的程序代码是这样的

【问题讨论】:

标签: python email if-statement logic


【解决方案1】:

您的问题在于您正在检查凭据的 if 条件。

你写过:

if emailstatus==True and email in UserKeys==True and UserKeys[email]==key:

在这里你可以做两件事:

1) 要么删除==True

改动后(一):if emailstatus==True and email in UserKeys and UserKeys[email]==key:

2) 或将电子邮件放在 UserKeys 的括号中,如下所示:(email in UserKeys)==True

修改后(2):if emailstatus==True and (email in UserKeys)==True and UserKeys[email]==key:

实际上如果email in UserKeys 返回True 如果该电子邮件存在,那么您不必明确检查它

【讨论】:

  • 谢谢!这就是问题所在。不幸的是,我是新手,还不能投票给你:c
  • 没关系。很高兴这有帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-26
  • 1970-01-01
  • 2021-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多