if、if elif判断

1、if.py

 #coding=utf-8
user = 'alex'
passwd = 'alex3714' username = input('username:')
password = input('password:') if user == username:
print ('username is correct...')
if passwd == password:
print ('Welcome login...')
else:
print('password is invalid...')
else:
print('连用户名都没蒙对,滚粗。。。')

2、if优化版.py

 #coding=utf-8
user = 'alex'
passwd = 'alex3714' username = input('username:')
password = input('password:') if user == username and passwd == password:
print ('Welcome login...')
else:
print('Invalid username or password...')

3、猜年龄

guess_age.py

 #coding=utf-8
age = 22
guess_num = int(input('input your guess num:'))
if guess_num == age:
print ('Congratulations!you got it.')
elif guess_num > age:
print ('Think smaller!')
else:
print ('Think big...')
上一篇:python库学习笔记——分组计算利器:pandas中的groupby技术


下一篇:Dockerfile指令详解下