PCC Chapter 4

Run Settings
LanguagePython
Language Version
Run Command
my_foods = ['pizza', 'sushi', 'steak', 'salad', 'noodles', 'low carb'] friend_foods = my_foods[:] my_foods.append('ice cream') friend_foods.append('vegan') print("My favorite foods are:") print(my_foods) print("\n\nMy friend's favorite foods are:") print(friend_foods) #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("\n" * 3) print("These are the first three of my favorite foods:") print(my_foods[0:3]) print("\nThese are the first three of the favorite foods of my friend.") print(friend_foods[0:3]) #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("\nThese are three items form the middle of my favorite") print(my_foods[1:4]) print("\nThese are three items from the middle of my friend's favorite foods") print(friend_foods[2:5]) #Print the message "The last three items in the list are:". #Use a slice to print the last three items in the list print("\nThe last three items in my list are:") print(my_foods[-3:]) print("\nThe last three items in my friends list are:") print(friend_foods[-3:]) print(" - " * 10) print("4-1") print("Think of at least three kinds of your favorite pizza.") pizzas = ['salami', 'cheese', 'tomato', 'bianco'] for pizza in pizzas: print(pizza) print(f"I really like {pizza.title()}-pizza.") print("\nI really really like pizza!") friend_pizzas = pizzas[:] pizzas.append('mushroom') friend_pizzas.append('chocolate') print("\nHere are the friend list with the appended items") for pizza in pizzas: print(pizza) print("\n") for friend_pizza in friend_pizzas: print(friend_pizza)
Editor Settings
Theme
Key bindings
Full width
Lines