Created
May 30, 2020 21:39
-
-
Save jmangrad/72fb886abffeb0f3386108f2f5729727 to your computer and use it in GitHub Desktop.
Python Crash Course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4-10. Slices: Using one of the programs you wrote in this chapter, add several | |
lines to the end of the program that do the following: | |
• Print the message The first three items in the list are:. Then use a slice to | |
print the first three items from that program’s list. | |
• Print the message Three items from the middle of the list are:. Use a slice to | |
print three items from the middle of the list. | |
• Print the message The last three items in the list are:. Use a slice to print the | |
last three items in the list. | |
4-11. My Pizzas, Your Pizzas: Start with your program from Exercise 4-1 | |
(page 56). Make a copy of the list of pizzas, and call it friend_pizzas. | |
Then, do the following: | |
• Add a new pizza to the original list. | |
• Add a different pizza to the list friend_pizzas. | |
• Prove that you have two separate lists. Print the message My favorite | |
pizzas are:, and then use a for loop to print the first list. Print the message | |
My friend’s favorite pizzas are:, and then use a for loop to print the second | |
list. Make sure each new pizza is stored in the appropriate list. | |
4.10 Answer | |
cities = ["london", "munich", "cancun", "paris", "tokyo"] | |
print(cities[0:4]) | |
print(cities[2]) | |
print(cities[2:]) | |
4.11 Answer | |
pizzas = ["less cheese", "pineapple", "no pepperroni"] | |
friend_pizzas = ["less cheese", "pineapple", "no pepperroni"] | |
pizzas.append("barbecue") | |
friend_pizzas.append("Crust") | |
for pizza in pizzas: | |
print(pizza) | |
print() | |
for friend_pizza in friend_pizzas: | |
print(friend_pizza) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment