1. Morse code is an early form of digital communication , It passed “·” and “-” To represent different English letters in different order , Numbers and punctuation . Try to write the program , Use a dictionary to store the contents of the table below , The string that will be entered by the user ( Suppose only English letters are included ) Output in the form of Morse code .
dic_morse={"A":"•−","B":"−•••","C":"−•−•","D":"−••","E":"•","F":"••−•","G":
"−−•", "H":"••••","I":"••","J":"•−−−","K":"−•−","L":"•−••","M":"−−","N":"−•",
"O":"−−−","P":"•−−•","Q":"−−•−","R":"•−•","S":"•••","T":"−", "U":"••−","V":
"•••−","W":"•−−","X":"−••−","Y":"−•−−","Z":"−−••"} s=input(" Please enter a string ( Contains only letters ):").
upper() morse_code="" for c in s: morse_code+=dic_morse[c] print(morse_code)
# sample output

Please enter a string ( Contains only letters ):abcd
•−−•••−•−•−••

2. Programming , Realize the following functions :
(1) Create an empty dictionary dic_student.
(2) The user enters the names and ages of five students in turn , Put it in the dictionary dic_student.
(3) Output dictionary dic_student Content in , The format is :
Wang Jian 18
Zhang Yun 19
Zhang Qiuyu 18
Liu Huan 17
Jiang Yu 19
dic_student={} for i in range(1,6): name=input(" Please enter page "+str(i)+" The names of the students :") age=
input(" Please enter page "+str(i)+" The age of a student :") dic_student[name]=age for k,v in dic_student.
items(): print("{:<3}\t{} year ".format(k,v))
# Output results

Please enter page 1 The names of the students : Wang Jian
Please enter page 1 The age of a student :18
Please enter page 2 The names of the students : Zhang Yun
Please enter page 2 The age of a student :19
Please enter page 3 The names of the students : Zhang Qiuyu
Please enter page 3 The age of a student :18
Please enter page 4 The names of the students : Liu Huan
Please enter page 4 The age of a student :17
Please enter page 5 The names of the students : Jiang Yu
Please enter page 5 The age of a student :19
Wang Jian 18 year
Zhang Yun 19 year
Zhang Qiuyu 18 year
Liu Huan 17 year
Jiang Yu 19 year

3. The following is the price list of products on sale of an e-commerce seller .
surface 7-2
Product name price / element
Sugar cube 99
X1499
NextBox 399
Try to write the program , Realize the following functions :
(1) Using a dictionary myDict Storage table 7-2 Information in , Product name as key , Price as value .
(2) Output price list of all products on sale . The format is
Sugar cube …………99 element
X1 …………499 element
NextBox …………399 element
Cookies …………299 element
(3) Output price of all products .
(4) The price of the product with the highest output price .
myDict={' Sugar cube ':99,'x1':499,' NextBox ':399,' Cookies ':299} print('\t Price List ') for k,v in myDict.
items(): print(k+'\t…………\t'+str(v)) lst=[] for v in myDict.values(): lst.append(
v) print(' The average price of all products is :{}'.format(sum(lst)/len(lst))) newlst=[(v,k) for k,v in
myDict.items()] newlst.sort() print(' What is the most expensive product :{}'.format(newlst[-1][1]))
# Output results

Sugar cube ………… 99
x1 ………… 499
NextBox ………… 399
Cookies ………… 299
The average price of all products is :324.0
What is the most expensive product :x1

4. Programming , Realize the following functions :
(1) Create an empty dictionary dic_student.
(2) The user enters the name of the student in turn , Age , Weight gain and weight gain , Put it in the dictionary dic_student, Use name as key , Age , Weight gain and weight were taken as the values .
(3) Output dictionary dic_student Content of .
dic_student={} for i in range(1,6): name=input(" Please enter page "+str(i)+" The names of the students :") age=
input(" Please enter page "+str(i)+" The age of a student :") height=input(" Please enter page "+str(i)+" The height of a student :") weight=
input(" Please enter page "+str(i)+" The weight of a student :") dic_student[name]=[age,height,weight] for k,v in
dic_student.items(): print("{:<3}\t{} year \t{}cm\t{}kg".format(k,v[0],v[1],v[2]))
# Output results

Please enter page 1 The names of the students : Wang Jian
Please enter page 1 The age of a student :18
Please enter page 1 The height of a student :172
Please enter page 1 The weight of a student :80
Please enter page 2 The names of the students : Zhang Yun
Please enter page 2 The age of a student :19
Please enter page 2 The height of a student :165
Please enter page 2 The weight of a student :55
Please enter page 3 The names of the students : Zhang Qiuyu
Please enter page 3 The age of a student :18
Please enter page 3 The height of a student :178
Please enter page 3 The weight of a student :82
Please enter page 4 The names of the students : Liu Huan
Please enter page 4 The age of a student :17
Please enter page 4 The height of a student :169
Please enter page 4 The weight of a student :75
Please enter page 5 The names of the students : Jiang Yu
Please enter page 5 The age of a student :19
Please enter page 5 The height of a student :170
Please enter page 5 The weight of a student :70
Wang Jian 18 year 172cm 80kg
Zhang Yun 19 year 165cm 55kg
Zhang Qiuyu 18 year 178cm 82kg
Liu Huan 17 year 169cm 75kg
Jiang Yu 19 year 170cm 70kg

5. Programming , Realize the following functions :
(1) Create an empty dictionary dic_student.
(2) Input the students' classes in turn by the user , full name , Age , Weight gain and weight gain , Put it in the dictionary dic_student, Use name as key , Age , Weight gain and weight were taken as the values .
(3) Output dictionary dic_student Content of .
dic_student={} for i in range(1,6): Class=input(" Please enter page "+str(i)+" A student's class :") name=
input(" Please enter page "+str(i)+" The names of the students :") age=input(" Please enter page "+str(i)+" The age of a student :") height=input(
" Please enter page "+str(i)+" The height of a student :") weight=input(" Please enter page "+str(i)+" The weight of a student :") dic_student[(
Class,name)]=[age,height,weight] for k,v in dic_student.items(): print(
"{:<3}\t{}\t{} year \t{}cm\t{}kg".format(k[0],k[1],v[0],v[1],v[2]))
# Output results

And 4 In the same way, I input five students' classes in turn , full name , Age , Just raise your body weight

6. Hypothetical dictionary variable dic_country It stores the corresponding relationship between the country name and the capital name of some countries , Where the country name is the key , The capital name is value . Try to write the program , Query the capital name according to the country name entered by the user , If it exists, the query result will be output , Otherwise prompt “ The country name was not queried !”. Assume that the country name is not case sensitive .
dic_country={"China":"Beijing","America":"Washington","Norway":"Oslo","Japan":
"Tokyo","Germany":"Berlin","Canada":"Ottawa","France":"Paris","Thailand":
"Bangkok"} country=input(" Please enter the country name :").lower().capitalize() if country in
dic_country: print(" The name of the capital :{}".format(dic_country[country])) else: print(
" The name of the country was not found !")
# sample output

Please enter the country name :China
The name of the capital :Beijing

7. Try to write the program , Realize the following functions :
(1) Create a dictionary , Store the user names and passwords of all registered users , The content is shown in the table 7-4 As shown in .
surface 7-4
User name and password
John123
Maryy111
Tommy123456
(2) Prompt the user to enter the user name and password .
(3) Judge the user name and password in turn , And give the corresponding tips .
If the user name is entered incorrectly , Then prompt “ Incorrect user name !”
If the password is wrong , Then prompt “ The password is incorrect !”
If the user name and password are correct , Then prompt “ Successful login !”
myDict={"John":"123","Marry":"111","Tommy":"123456"} username=input(' enter one user name :')
if username not in myDict: print(' The user does not exist !') else: password=input(' Please input a password :') if
password!=myDict[username]: print(' The password is incorrect !') else: print(' Login successfully !')
# sample output

enter one user name :Tommy
Please input a password :123456
Login successfully !

8. It's the end of the year , A company is going to give a year-end bonus . list lst_staff A list of all the employees is kept in , The content is [“ Li Mei ”,“ Zhang Fu ”,“ Fu Yan ”,“ Zhao Nuo ”,“ Liu Jiang ”]. Dictionaries dic_award The list of employees who have made outstanding contributions to the company and the amount of bonus are stored in , The content is {“ Zhang Fu ”:10000,“ Zhao Nuo ”:15000}. Try to write the program , Output the amount of annual bonus payable to each employee .dic_award The amount of year-end bonus not included in is 5000 element / people .
lst_staff=[" Li Mei "," Zhang Fu "," Fu Yan "," Zhao Nuo "," Liu Jiang "] dic_award={" Zhang Fu ":10000," Zhao Nuo ":15000} for x in
lst_staff: if x in dic_award: print("{} annual bonus :{} element ".format(x,dic_award[x])) else:
print("{} annual bonus :{} element ".format(x,5000))
# Output results

Li Mei's year end bonus :5000 element
Zhang Fu's year end bonus :10000 element
Fu Yan's year end bonus :5000 element
Zhao Nuo year end bonus :15000 element
Liu Jiang's year end bonus :5000 element

9. Hypothesis list lst_busstop=[“ Longjiang new city ”,“ Sunshine Plaza ”,“ Hanjiang Road ”,“ Nenjiang Road ”,“ Qingliangshan Park ”,“ Lhasa Road ”,“ Wutai Mountain ”,“ Mochou Road ”], The name of the bus station where a bus route is stored . There is another dictionary dic_estate={“ Longjiang new city ”:[“ Baiyun Garden ”,“ Take off Garden ”],“ Sunshine Plaza ”:[“ Longjiang District ”,“ Fangcaoyuan ”],“ Hanjiang Road ”:[“ Jinxin Garden ”,“ Longfeng Garden "],“ Nenjiang Road ”:[“ Blue Bay in Xicheng ”,“ Flowers bloom all the year round ”]}, Some residential areas near bus stops are stored . Try to write the program , According to the starting point entered by the user ( Community name ) And the end ( Community name ), Query bus routes . for example , The starting point is “ Baiyun Garden ”, End “ Longfeng Garden ”, The output result is “ Starting station : Longjiang new city station , Terminus : Hanjiang Road Station , common 2 station ”. If the starting point is “ Longfeng Garden ”, The destination is “ Baiyun Garden ”, Then output “ You need to take the opposite route ”.
lst_busstop=[" Longjiang new city "," Sunshine Plaza "," Hanjiang Road "," Nenjiang Road "," Qingliangshan Park "," Lhasa Road "," Wutai Mountain "," Mochou Road "] dic_estate=
{" Longjiang new city ":[" Baiyun Garden "," Take off Garden "]," Sunshine Plaza ":[" Longjiang District "," Fangcaoyuan "]," Hanjiang Road ":[" Jinxin Garden "," Longfeng Garden "]," Nenjiang Road ":[" Blue Bay in Xicheng "
," Flowers bloom all the year round "]} start=input(" Please enter the starting point ( Community name ):") end=input(" Please enter the destination ( Community name ):") for k,v in
dic_estate.items(): if start in v: startStop=k break for k,v in dic_estate.items
(): if end in v: endStop=k break startIndex=lst_busstop.index(startStop)
endIndex=lst_busstop.index(endStop) if startIndex>endIndex: print(" You need to take the opposite route .")
else: print(" starting station :{} station , Terminus :{} station , common {} station .".format(startStop,endStop,endIndex-startIndex
))
# sample output

Please enter the starting point ( Community name ): Baiyun Garden
Please enter the destination ( Community name ): Longfeng Garden
starting station : Longjiang new city station , Terminus : Hanjiang Road Station , common 2 station .

10. Hypothetical dictionary dic_city It stores the cities that everyone has visited , The content is {“ Zhang Sanfeng ”:[“ Beijing ”,“ Chengdu ”],“ Li Mo silk ”:[“ Shanghai ”,“ Guangzhou ”,“ Lanzhou ”],“ Muronghai ”:[“ Taiyuan ”,“ Xi'an ”,“ Jinan ”,“ Shanghai ”]}. Try to write the program , Realize the following functions .
(1) Count the number of cities that each person has visited .
(2) Count the number and list of people who have been to Shanghai .
dic_city={" Zhang Sanfeng ":[" Beijing "," Chengdu "]," Li Mo silk ":[ " Shanghai ", " Guangzhou ", " Lanzhou "], " Murongfu ":[ " Taiyuan ", " Xi'an "," Jinan ",
" Shanghai "]} for k,v in dic_city.items(): print("{} Yes {} Cities ".format(k,len(v))) name=[]
for k,v in dic_city.items(): if " Shanghai " in v: name.append(k) print(
" Who have been to Shanghai {} people , They are {}".format(len(name),",".join(name)))
# Output results

Zhang Sanfeng has been there 2 Cities
Li Mo silk has been there 3 Cities
Murong Fu has been there 4 Cities
Who have been to Shanghai 2 people , They are Li Mo silk , Murongfu

11. Suppose you have a dictionary variable dic_score The information of students' grades is stored ( See table 7-5), Name as key . Try to write the program , Count the average score of each student , Add to dictionary , Finally, output the dictionary .
surface 7-5
Name Chinese mathematics English computer average score
Xu Li 8890989592.75
Zhang Xing 8592959892.5
Liu Ning 8989909290.0
Zhang Xu 8286899086.75 dic_score={" Xu Li ":[88,90,98,95]," Zhang Xing ":[85,92,95,98]," Liu Ning ":[89,89,90
,92]," Zhang Xu ":[82,86,89,90]} for k,v in dic_score.items(): dic_score[k].append(sum(v
)/len(v)) print(" full name \t chinese \t mathematics \t English \t computer \t average ") for k,v in dic_score.items(): print(
k,end="\t") for x in v: print(x,end="\t") print()
# Output results

full name chinese mathematics English computer average
Xu Li 88 90 98 95 92.75
Zhang Xing 85 92 95 98 92.5
Liu Ning 89 89 90 92 90.0
Zhang Xu 82 86 89 90 86.75

Technology
©2019-2020 Toolsou All rights reserved,
2020 The 11th National Blue Bridge Cup C/C++b Group summary ( Completion ) Review of the most complete computer network principles in history vue-cli 3 VUE Scaffold project construction ( Detailed explanation ) solve Vue+TypeScript Under development TS Don't recognize this.$refs The question of Vue Using the function of anti chattering and throttling How to use division operation in relational algebra SQL Statement representation ?copy-webpack-plugin Copy and compress files avue The use of dictionaries in English Teaching girls to learn Java: What is? Java?python Code painting Cherry Blossom -python Draw cherry tree code Specific code introduction