Python exercise: 4-1. Food: Think of three kinds of your favorite food and store the food names in a list. Use a for loo
Posted: Thu May 26, 2022 9:20 am
Python exercise:
4-1. Food: Think of three kinds of your favorite
food and store the food names in a list.
Use a for loop to print the name of each food.
Modify your loop to print a sentence using the name of the food
instead of printing just
the name, for example, "I like bananas."
Add a line at the end of your program, outside
the for loop, that states how much you like
food, for example, "I really enjoy food!"
4-2. Animals: Think of five different animals and
store the names of the animals in a list.
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 something these
animals have in common,
for example, "Any of these animals would make a great pet!"
4-3. Counting to Twenty:
• Use a for loop to print the numbers from 1 to
20, inclusive. • Use the sum() function to add
the numbers from 1 to 20.
4-4. Counting to One Million:
Make a list of the numbers from one to one million but do
not print the numbers!
Use min() and max() to show that the list
starts at one and ends at one million.
Use the sum() function to see how quickly Python can
add a million numbers.
4-1. Food: Think of three kinds of your favorite
food and store the food names in a list.
Use a for loop to print the name of each food.
Modify your loop to print a sentence using the name of the food
instead of printing just
the name, for example, "I like bananas."
Add a line at the end of your program, outside
the for loop, that states how much you like
food, for example, "I really enjoy food!"
4-2. Animals: Think of five different animals and
store the names of the animals in a list.
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 something these
animals have in common,
for example, "Any of these animals would make a great pet!"
4-3. Counting to Twenty:
• Use a for loop to print the numbers from 1 to
20, inclusive. • Use the sum() function to add
the numbers from 1 to 20.
4-4. Counting to One Million:
Make a list of the numbers from one to one million but do
not print the numbers!
Use min() and max() to show that the list
starts at one and ends at one million.
Use the sum() function to see how quickly Python can
add a million numbers.