手记

python中if else流程判断

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:
...

0人推荐
随时随地看视频
慕课网APP