ITPub博客

首页 > IT职业 > IT图书 > python中if else流程判断

python中if else流程判断

IT图书 作者:ylwtsmt 时间:2021-09-09 09:34:11 0 删除 编辑

1、python中实现密码密文输入

#!/usr/bin/env pythonimport getpass   #调用getpass模块就能实现密码密文显示username=input("username:")userpasswd=getpass.getpass("userpasswd:")print(username,userpasswd)

2、if 判断

(1)、

#!/usr/bin/env python_username = "lijinzhu"_userpasswd = "abc123"username = input("username:")userpasswd = input("userpasswd:")if _username == username and _userpasswd == userpasswd:    print("Welcome usr {name} login...".format(name=username))else:    print("Invalid username or passwd!")

(2)、猜年龄

#!/usr/bin/env python_age = 18age = int(input("age:"))if _age == age:    print("right")elif _age > age:    print("think smaller...")else:    print("think strong...")

#Note:
if 条件判断:  
...
elif 条件判断:
...
else:
...

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4505/viewspace-2804787/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-09

  • 博文量
    81
  • 访问量
    719