1 user='liangml' 2 passwd='liangml' 3 username=input('username:') 4 password=input('password:') 5 #优化前 6 ''' 7 if user == username: 8 print('usernameiscorrect...') 9 if passwd == password: 10 print('welcomelogin...') 11 else: 12 print('passwordifinvalid...') 13 else: 14 print('user name is not...') 15 ''' 16 ''' 17 #优化后 18 if user == username and passwd == password: 19 print('Welcomelogin') 20 else: 21 print('Invalid user name or password...') 22 ''' 23 24 --------------------分界线---------------------- 25 If语句猜年龄小游戏 26 age=22 27 guess_num=int(input('inputyourguessnum:')) 28 if guess_num==age: 29 print('Congratulations!yougotit.') 30 elif guess_num>age: 31 print('Thinksmaller!') 32 else: 33 print('ThinkBig...')