if else 判断交流

1.判断用户名密码对不对。

 1 import getpass
 2 _username = 'devin'
 3 _password = 'abc123'
 4 username = input("username:")
 5 #password = getpass.getpass("password:")
 6 password = input("password:")
 7 if _username == username and _password == password:
 8   print("Welcome user {name} login...".format(name=username))
 9 else:
10   print("Invalid username or password!")

注:判断语句,print需要\tab不可以与if并列。强制缩进。

if:条件语句

and:并且

or:或者

==:等于

else:如果不成立就执行下面

 

注:判断语句

elif:代表如果不成立或者的意思。

python3默认识别的是字符串,数字需要转换为int数字。

 

相关文章:

  • 2021-08-15
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2021-10-02
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-15
  • 2021-10-09
相关资源
相似解决方案