首页 > 代码库 > python学习之if语句

python学习之if语句

1. 判断输入的字符是否一致

SIZE="hello"
char=input("输入字符名称:")
if char == SIZE:
    print("字符名称%s"%char,"等于",SIZE)
else:
    print("请输入字符",SIZE)

2.判断登录验证用户名密码

user="desperado"
pwd="123456"

username=input("用户名:")
password=input("密码:")

if username == user and password == pwd:
    print("login successful ...")
elif username != user:
    print("the user does not exist")
else:
    print("login fail")

  

python学习之if语句