Python small exercise (8)

Time:2022-5-22
from list_sort_practise import practical_travel_list
from list_slice import my_foods,friend_foods
#4-10 slicing: select a program you write in this chapter and add a few lines of code at the end to finish
#The tasks are as follows.
#Print the message "the first three items in the list are:", and then use the slice to print the list
#The first three elements of.
#Print the message "three items from the middle of the list are:", and then use the slice to print
#Print the three elements in the middle of the list.
#Print the message "the last three items in the list are:", and then use the slice to print the list
#The last three elements.
print("The first three items in the list are:",practical_travel_list[0:3])
print('-------------------------------------------------------------------')

print("Three items from the middle of the list are:",practical_travel_list[1:4])

print('-------------------------------------------------------------------')
print("The last three items in the list are:",practical_travel_list[2:])
print('-------------------------------------------------------------------')

#4-11 your pizza and my pizza: in the program you wrote to complete exercise 4-1, create a ratio
#A copy of the SA list and store it in the variable friend_ In pizza, complete the following tasks
#Business.
#Add a pizza to the original pizza list.
#In the list friend_ Add another pizza to pizza.
#Verify that you have two different lists. To do this, print the message "my favorite pizza are:",
#Then use a for loop to print the first list; Print the message "my friend's favorite"
#Pizza are: ", and then use a for loop to print the second list. Verify the new ratio
#SA was added to the correct list.
my_pizzas=['sudi','sipa','shuiguo']
friend_pizzas = my_pizzas[:]

my_pizzas.append('sala')
friend_pizzas.append('shuiguo')
print("My favorite pizzas are:")
print(my_pizzas)

print("My friend's favorite pizzas are:")
print(friend_pizzas)
print('-------------------------------------------------------------------')
#4-12 use multiple cycles: in this section, in order to save space, the program foods Every version of PY
#The for loop is not used to print the list. Please select a version of foods Py, in which to write
#Two for loops to print out each food list.
for  my_food in my_foods:
    Print ('My favorite food is: ', my_food)
for friend_food in friend_foods:
    Print ("friends' favorite food is:", friend_food)

results of enforcement

The first three items in the list are: ['yading', 'xianggelila', 'weizhoudao']
-------------------------------------------------------------------
Three items from the middle of the list are: ['xianggelila', 'weizhoudao', 'sanya']
-------------------------------------------------------------------
The last three items in the list are: ['weizhoudao', 'sanya', 'dali']
-------------------------------------------------------------------
My favorite pizzas are:
['sudi', 'sipa', 'shuiguo', 'sala']
My friend's favorite pizzas are:
['sudi', 'sipa', 'shuiguo', 'shuiguo']
-------------------------------------------------------------------
My favorite food is pizza
My favorite food is falafel
My favorite food is carrot cake
My favorite food is Cannoli
A friend's favorite food is pizza
Friend's favorite food is falafel
My friend's favorite food is carrot cake
My friend's favorite food is ice cream
Hahaha, the list is finished!

The process has ended with exit code 0

Recommended Today

Source code analysis of distributed scheduling engine elastic job (II) job and registration based V3

1. Background The scheduling engine is the key infrastructure. It not only executes tasks regularly, but also is a large-scale distributed task engine, distributed parallel processing platform, manages the cluster of computing nodes, and provides scalable data processing capacity with high throughput. With the growing business of the company, the requirements for high throughput and […]