topic:
5-3 Alien color # 1: Assume that in the game just shot and killed an alien, create a variable named alien_color, and set it to 'green', 'yellow' or 'red'.
Write an if statement to check whether an alien is green; if so, print a message saying that players get 5 points.
Two versions of this program written in a version by the above tests, and in another version not passed (no output test fails).
5-4 Alien # 2 Color: as practicing 5-3 to set the color as aliens, and write a if-else structure.
If the alien is green, it prints a message stating that the player due to shooting the aliens gained 5 points.
If the alien is not green, it prints a message saying that players get 10 points.
Two versions of the program write is performed if block in one version, the code block is executed else in another version.
5-5 alien color # 3: Exercise if-else structure was changed to 5-4 if-elif-else structure.
If the alien is green, it prints a message saying that players get 5 points.
If the alien is yellow, it prints a message saying that players get 10 points.
If the alien is red, it prints a message saying that players get 15 points.
Three versions of the preparation of this procedure, they were aliens in green, a message is printed when yellow and red.
5-6 is not all men are born different stages of the same order segment: age of the value of a variable, then write an if-elif-else structure, which is in the stage of life based on the value judgment of age.
If a person younger than 2 years old, print a message that he is a baby.
If a person's age is 2 (inclusive) to 4 years old, it prints a message that he was a toddler.
If a person's age is 4 (inclusive) to 13 years of age, it prints a message that he is a child.
If a person's age to 13 (inclusive) to 20 years of age, print a message that he is young people.
If a person's age to 20 (inclusive) to 65 years, print a message that he is an adult.
If a person over the age of 65 (inclusive) years old, it prints a message that he is older.
5-7 favorite fruit: create a list that contains your favorite fruit, then write a series of separate if statement to check the list contains a specific fruit.
Name the list favorite_fruits, and contains three fruits.
5 if written statement, some kind of fruit each have to check is included in the list, if included in the list, it prints a message such as "You really like bananas!".
Code:
#!usr/bin/python # _*_ coding:utf-8 _*_ #外星人颜色 alien_color = "blue" if alien_color == "blue": print("You got 5 star") if alien_color == "blue": print("测试通过,外星人为蓝色") if alien_color == "blue": print("") #外星人颜色#2 #版本1 killed_alien_color = "blue" if killed_alien_color == "blue": print("You got 5 star,cause you killed him") else: print("You got 10 star") #版本2 if killed_alien_color == "yellow": print("You got 5 star,cause you killed him") else: # 1 version # 3 Color Alien Print ( "Star by You GOT 10") kill_alien_color = "Blue" if kill_alien_color =="blue": print("You got 5 star") elif kill_alien_color == "yellow": print("You got 10 star") else: print("You got 15 star") #版本2 kill_alien_color = "yellow" if kill_alien_color =="blue": print("You got 5 star") elif kill_alien_color == "yellow": print("You got 10 star") else: print("You got 15 star") #版本3 kill_alien_color = "red" if kill_alien_color =="blue": print("You got 5 star") elif kill_alien_color == "yellow": # various stages of life Print ( "Star by You GOT 15") the else: Print ( "GOT 10 Star by You") age = 17 if age < 2: print("he was a baby!") elif age >=2 and <4: print("Is he learning how to walk!") elif age >=4 and <13: print("he was a chird!") elif age >=13 and <20: print("he was a teenager!") elif age >=20 and <65: print("You are adult!,Young man!") else: print("You are old!") #喜欢的水果 favorite_fruits = ["bananas","watermalon","apples","oranges","pears"] if "bananas" in favorite_fruits: print("You are really like bananas!") if "watermalon" in favorite_fruits: print("You are really like watermalon!") if "apples" in favorite_fruits: print("You are really like apples!") if "oranges" in favorite_fruits: print("You are really like oranges!") if "pears" in favorite_fruits: print("You are really like pears!")