5-3/4/5 外星人的颜色
#5.3 alien_color='green' if alien_color=='green': print("You got 5 points") if alien_color=='red': print("You got 5 points") print("\n") #5.4 if alien_color=='green': print("You got 5 points") else: print("You got 10 points") alien_color='red' if alien_color=='green': print("You got 5 points") else: print("You got 10 points") print("\n") #5.5 alien_color='green' if alien_color=='green': print("You got 5 points") elif alien_color=='yellow': print("You got 10 points") else: print("You got 15 points") print("\n") alien_color='yellow' if alien_color=='green': print("You got 5 points") elif alien_color=='yellow': print("You got 10 points") else: print("You got 15 points") print("\n") alien_color='red' if alien_color=='green': print("You got 5 points") elif alien_color=='yellow': print("You got 10 points") else: print("You got 15 points")
5-6 人生的不同阶段
age=int(input("Please enter a man's age:")) if age<2: print("He is a baby.") elif age>=2 and age<4: print("He is at the age of learning walking.") elif age>=4 and age<13: print("He is a child.") elif age>=13 and age<20: print("He is a teenager.") elif age>=20 and age<54: print("He is an adult.") else: print("He is an old")
5-8以特殊方式和管理员打招呼
name=("admin",'A','B','C','D') for login in name: if login=='admin': print("Hello admin,would you like to see a status report?") else: print("Hello "+login+",thank you for logining in again.")