4-1 Pizza:Think of at least three of your favorite pizzas, store their names in a list, and use the For loop to print out the name of each pizza.
Modify the For loop so that it prints a sentence that contains the name of the pizza, not just the name of the pizza. For each pizza, a line of output, such as "I like pepperoni pizza", is displayed.
Pizzas = [' cheese pizza ', ' Durian pizza ', ' seafood pizza ']
For pizza in Pizzas:
(space) print ("I like" + Pizza.title ())
-
- Add a line of code at the end of the program that doesn't indicate how much you like pizza in the For loop. The output should contain messages for each pizza and a concluding sentence, such as: "I really love pizza!" ”。
Pizzas = [' cheese pizza ', ' Durian pizza ', ' seafood pizza ']
For pizza in Pizzas:
(space) print ("I like" + Pizza.title ())
Print (I really love pizza!)
4-2 Animals: Think of at least three species of animals with common characteristics, store the names of these animals in a list, and then use the For loop to print out the names of each animal.
- Modify the program so that it prints a sentence for each animal, such as "a dog would make a great pet!"
Animals = [' dog ', ' cat ', Rabbit ']
For animal in animals:
(space) print ("a" + animal.title () "+" would make A great pet ")
- Add a line of code at the end of the program to indicate what these animals have in common, such as printing "any of these animals would make a great pet!"
Animals = [' dog ', ' cat ', Rabbit ']
For animal in animals:
(space) print ("a" + animal.title () "+" would make A great pet ")
Print ("Any of these animals would make a great pet!")
Python 4.1 traverse the entire list (try it out)