Working with For-loops exercises 1

python

4-1. Pizzas: Think of at least three kinds of your favorite pizza. Store these pizza names

  • in a list, and then use a for loop to print the name of each pizza.Modify your for loop to print a sentence using the name of the pizza instead of printing just the name of the pizza. For each pizza you should have one line of output containing a simple statement like I like pepperoni pizza.
  • Add a line at the end of your program, outside the for loop,that states how much you like pizza. The output should consist of three or more lines about the kinds of pizza you like and then an additional sentence, such as I really love pizza!

4-2. Animals: Think of at least three different animals that have a common
characteristic. Store the names of these animals in a list, and then use a for loop to print out the name of each animal.

  • Modify your program to print a statement about each animal,such as A dog would make a great pet.
  • Add a line at the end of your program stating what these animals have in common. You could print a sentence such as Any of these animals would make a great pet!

4-1 Answer :

pizza_species = ['pepperoni','fish','cheese']
for favourite_pizza in pizza_species:
	print(f"I like {favourite_pizza.title()} pizza.")
print("I really love pizza")
Output :
I like Pepperoni pizza.
I like Fish pizza.
I like Cheese pizza.
I really love pizza

4-2 Answer:

animal = ['dog','cat','parrot']
for pet in animal:
	print(f"{pet.title()} would make a great pet")
print("Any of these animals would make a great pet!")
Output :
Dog would make a great pet
Cat would make a great pet
Parrot would make a great pet
Any of these animals would make a great pet!

Popular posts from this blog

Mustacchio - TryHackMe

Tech_Supp0rt: 1 - TryHackMe