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...')