1. Suppose there are three lists :lst_who=[“ pony ”,“ lamb ”,“ fawn ”],lst_where=[“ On the grass ”,“ cinema ”,“ of one's own unit ”],lst_what=[“ watch movie ”,“ Listen to the story ”,“ sup on ”]. Try to write the program , Randomly generate three 0-2 Integer in range , Use it as an index to access the corresponding elements in the three lists , Then make sentences . for example , Randomly generate three integers, which are 1,0,2, Then output the sentence “ The lamb is having dinner on the grass ”.
import random lst_who=[" pony "," lamb "," fawn "] lst_where=[" On the grass "," cinema "," of one's own unit "] lst_what=[
" watch movie "," Listen to the story "," sup on "] a,b,c=random.randint(0,2),random.randint(0,2),random.randint(
0,2) sentence=lst_who[a]+" stay "+lst_where[b]+lst_what[c] print(sentence)
# sample output

Deer listening to stories in the cinema

2. Programming , Realize the following functions :
(1) Create a list , Store the corresponding days of each month in turn . hypothesis 2 The number of days in a month is fixed at 28 day .
(2) Query the days of the month according to the month entered by the user and output .
lst_monthdays=[31,28,31,30,31,30,31,31,30,31,30,31] month=eval(input(" Please enter the month :"))
while month!=0: print("{} Month has {} day !".format(month,lst_monthdays[month-1])) month=
eval(input(" Please enter the month :")) print(" End of procedure !")
# sample output

4 Month has 30 day !

3. Fibonacci sequence is also called golden section sequence , Rabbit Series , Its first 1,2 Xiang Junwei 1, From the first 3 Each item is the sum of the first two days , Namely 1,1,2,3,5,8,13,21,34,…. Try to write the program , Using list to calculate Fibonacci sequence 30 term , And output .
lst=[1,1] for i in range(2,30): lst.append(lst[i-1]+lst[i-2]) print(lst)
# Output results

[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584,
4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229,
832040]

4. Hypothesis list lst_busstop=[“ Longjiang new city ”,“ Sunshine Plaza ”,“ Hanjiang Road ”,“ Nenjiang Road ”,“ Qingliangshan Park ”,“ Lazarus ”,“ Wutai Mountain ”,“ Mochou Road ”], The name of the bus station where a bus route is stored . Try to write the program , According to the user input starting station and terminal station , Calculate the number of stations that need to pass and output the results . for example , When the input starting station is “ Hanjiang Road ”, The terminal is “ Wutai Mountain ” Time , The output content is “ It is necessary to go from Hanjiang Road station to Wutaishan station 4 Station Road ”; When the input starting station is “ Wutai Mountain ”, The terminal is “ Hanjiang Road ” Time , output “ You need to call it the reverse route ”.
lst_busstop=[" Longjiang new city "," Sunshine Plaza "," Hanjiang Road "," Nenjiang Road "," Qingliangshan Park "," Lhasa Road "," Wutai Mountain "," Mochou Road "] startStop=
input(" Please enter the starting point :") endStop= input(" Please enter the terminal :") startIndex=lst_busstop.index(
startStop) endIndex=lst_busstop.index(endStop) if startIndex>endIndex: print(
" You need to take the opposite route .") else: print(" from {} Station to {} Station needs {} station .".format(startStop,endStop,endIndex-
startIndex))
# Output results

Please enter the starting point : Wutai Mountain
Please enter the terminal : Hanjiang Road
You need to take the opposite route .

5. Hypothesis list lst_student=[“001”,“ Li Mei ”,19,“002”,“ Liu Xiang ”,20,“003”,“ Zhang Wu ”,18], The student number of each student is stored in turn , full name , Age . Try to write the program , Realize the following functions :
(1) Add a table to the end of the list 6-1 Students' information in English .
surface 6-1
Student number name age
004 Liu Ning 20
006 Liang Feng 19
(2) Add a table in the appropriate place in the list 6-2 Student information for .
surface 6-2
Student number name age
005 Lin Ge 20
(3) The output student number is 003 Student information for .
(4) Output the names of all students .
(5) Output the average age of all students .
lst_student=["001"," Li Mei ",19,"002"," Liu Xiang ",20,"003"," Zhang Wu ",18] lst_new=["004"," Liu Ning ",20,
"006"," Liang Feng ",19] lst_student.extend(lst_new) lst_student.insert(lst_student.index(
"006"),"005") lst_student.insert(lst_student.index("006")," Lin Ge ") lst_student.
insert(lst_student.index("006"),20) print(lst_student[lst_student.index("003"):
lst_student.index("003")+3]) print(" Names of all students :",lst_student[1::3]) lst_age=
lst_student[2::3] print(" Average age of all students :{:.1f}".format(sum(lst_age)/len(lst_age)))
# Output results

[‘003’, ‘ Zhang Wu ’, 18]
Names of all students : [‘ Li Mei ’, ‘ Liu Xiang ’, ‘ Zhang Wu ’, ‘ Liu Ning ’, ‘ Lin Ge ’, ‘ Liang Feng ’]
Average age of all students :19.3

6. Suppose there is a list lst_student=[[“001”,“ Li Mei ”,19],[“002”,“ Liu Xiang ”,20],[“003”,“ Zhang Wu ”,18]], The student number of each student is stored in turn , Name and age . Try to write the program , Realize the following functions :
(1) Add a table to the end of the list 6-1 Information of middle school students .
(2) Add a table in the appropriate place in the list 6-2 Information of middle school students .
(3) The output student number is 003 Student information for .
(4) Output the names of all students .
(5) Output age greater than 19 All student information for .
lst_student=["001"," Li Mei ",19,"002"," Liu Xiang ",20,"003"," Zhang Wu ",18] lst_new=["004"," Liu Ning ",20,
"006"," Liang Feng ",19] lst_student.extend(lst_new) lst_student=[["001"," Li Mei ",19],["002",
" Liu Xiang ",20],["003"," Zhang Wu ",18]] lst_new=[["004"," Liu Ning ",20],["006"," Liang Feng ",19]] lst_student.
extend(lst_new) lst_student.insert(4,["005"," Lin Ge ",20]) print(" Student number is 003 Student information for :",
lst_student[2]) print(" Names of all students :",[x[1] for x in lst_student]) print(
" Older than 19 Information for all students :",[x for x in lst_student if x[2]>19])
# Output results

Student number is 003 Student information for : [‘003’, ‘ Zhang Wu ’, 18]
Names of all students : [‘ Li Mei ’, ‘ Liu Xiang ’, ‘ Zhang Wu ’, ‘ Liu Ning ’, ‘ Lin Ge ’, ‘ Liang Feng ’]
Older than 19 Information for all students : [[‘002’, ‘ Liu Xiang ’, 20], [‘004’, ‘ Liu Ning ’, 20], [‘005’, ‘ Lin Ge ’, 20]]

7. nail , B , C , One of the four did a good deed without leaving his name . Please write the program , Follow these clues to find out who is doing good .
nail : It wasn't me
B : It's C
C : It's Ding
Ding : C is wrong
Three of them are telling the truth , One person is lying .
lst=[' nail ',' B ',' C ',' Ding '] for x in lst: if (x!=' nail ') + (x==' C ')+ (x==' Ding ') +(x!=' Ding ')
==3: print(x) break
# Output results

C

8. In a math contest ,A,B,C,D,E The five students won the top five respectively ( Suppose there is no parallel place ). Xiaomin asked them which place they were , Their answers are as follows :
A: The second place is D, The third place is B
B: The second place is C, The fourth place is E
C: Number one is E, The fifth place is A
D: The third place is C, The fourth place is A
E: The second place is B, The fifth place is D
Each of them is only half right , Try to write the program , Help Xiaomin guess their real position .
import random ls = list('ABCDE') print(ls) while True: random.shuffle(ls) if (
ls[1]=='D') + (ls[2]=='B') == 1\ and (ls[1]=='C') + (ls[3]=='E') == 1\ and (ls[0
]=='E') + (ls[4]=='A') == 1\ and (ls[2]=='C') + (ls[3]=='A') ==1\ and (ls[1]==
'B') + (ls[4]=='D') ==1: print(ls) break
# Output results
['A', 'B', 'C', 'D', 'E'] ['E', 'C', 'B', 'A', 'D']
9. Programming , Use the list to store the names of ten students , And output the list result .
(1) The student's name is entered by the user in turn
(2) Prompt statement when input , as “ Please enter the name of the first student ”.
lst_studentname=[] for i in range(1,11): name=input(" Please enter page {} Name of student :".format(i))
lst_studentname.append(name) print(lst_studentname)
# sample output You can enter any ten names

Please enter page 1 Name of student : Zhang San
Please enter page 2 Name of student : Li Si
Please enter page 3 Name of student : Wang Wu
Please enter page 4 Name of student : Little tiger
Please enter page 5 Name of student : Xiao Ming
Please enter page 6 Name of student : Liu Xin
Please enter page 7 Name of student : Publicity
Please enter page 8 Name of student : Xie Xu
Please enter page 9 Name of student : Hutu
Please enter page 10 Name of student : Wei Yan
[‘ Zhang San ’, ‘ Li Si ’, ‘ Wang Wu ’, ‘ Little tiger ’, ‘ Xiao Ming ’, ‘ Liu Xin ’, ‘ Publicity ’, ‘ Xie Xu ’, ‘ Hutu ’, ‘ Wei Yan ’]

10. Revision questions 9 Procedures , Add the new name at the beginning of the list each time .
lst_studentname=[] for i in range(1,11): name=input(" Please enter page {} Name of student :".format(i))
lst_studentname.insert(0,name) print(lst_studentname)
Please enter page 1 Name of student : Zhang San
Please enter page 2 Name of student : Li Si
Please enter page 3 Name of student : Wang Wu
Please enter page 4 Name of student : Song Jiang
Please enter page 5 Name of student : Bear cub
Please enter page 6 Name of student : Xiao Ming
Please enter page 7 Name of student : Little plum
Please enter page 8 Name of student : Li Hao
Please enter page 9 Name of student : Faye Wong
Please enter page 10 Name of student : Li Jie
[‘ Li Jie ’, ‘ Faye Wong ’, ‘ Li Hao ’, ‘ Little plum ’, ‘ Xiao Ming ’, ‘ Bear cub ’, ‘ Song Jiang ’, ‘ Wang Wu ’, ‘ Li Si ’, ‘ Zhang San ’]

11. Hypothesis list lst_info=[[“ Li Yu ”,“ male ”,25],[“ Jin Zhong ”,“ male ”,23],[“ Liu Yan ”,“ female ”,21],[“ Mo Xin ”,“ female ”,24],[“ Shen Chong ”,“ male ”,28]], It stores the basic information of each employee in a certain unit ( Include name , Gender and age ). Try to write the program , It can delete the employee information required by users from the list .
(1) The name of the employee to be deleted is entered by the user .
(2) If the employee name entered by the user exists in the list , Then delete ; If it doesn't exist , The corresponding prompt is given .
(3) The program can be executed circularly , When the user enters the name as “0” Time , End of cycle .
lst_info=[[" Li Yu "," male ",25],[" Jin Zhong "," male ",23],[" Liu Yan "," female ",21],[" Mo Xin "," female ",24],[" Shen Chong "," male ",28]
] name=input(" Please enter the name of the employee you want to delete :") while name!="0": for info in lst_info: if info[0
]==name: lst_info.remove(info) print(" Deleted list :{}".format(lst_info)) break else:
print(" The employee's name does not exist in the list !") name=input(" Please enter the name of the employee you want to delete :") print(" End of procedure !")
# sample output

Please enter the name of the employee you want to delete : Li Yu
Deleted list :[[‘ Jin Zhong ’, ‘ male ’, 23], [‘ Liu Yan ’, ‘ female ’, 21], [‘ Mo Xin ’, ‘ female ’, 24], [‘ Shen Chong ’, ‘ male ’, 28]]
Please enter the name of the employee you want to delete : Zhang San
The employee's name does not exist in the list !
Please enter the name of the employee you want to delete :0
End of procedure !

There are too many questions. I'll try again next time

Technology