Download:springboot short video applet development full stack actual combat project
1。 Example of generation of four digit alphanumeric textual research code
Print ('login success')
write_ LogInfo (username) \\
show_ Info() \\
Num = int (input ('input operand: ')) \
while True:
if num == 0:
Print ('exit victory ')
break
elif num == 1:
Print ('view login log ')
read_loginfo()
show_info()
Num = int (input ('input operand: ')
else:
Print ('the number you entered is incorrect ')
show_info()
Num = int (input ('input operand: ')
3。 Imitate Taobao customer service to reply automatically
Copy code
1 \2 task 2: imitate Taobao customer service to reply automatically
2
3 def find_answer(question):
4 with open(‘reply.txt’,’r’) as f :
5 while True:
6 line=f.readline()
7 if not line: \\
8 break
9 keyword=line.split(‘|’)[0]
1
else:
Print ("leap year")
Copy code
6。 Python counts the number of numbers, letters, and Chinese characters in a string
Copy code
1 import re
2 str_ Test=’abcdefghabc123456 Chinese nation ‘
3
Compile the regular expression into an object. If the object is often used, this method can improve the efficiency
5 num_regex = re.compile(r'[0-9]’)
6 zimu_regex = re.compile(r'[a-zA-z]’)
7 hanzi_regex = re.compile(r'[\u4E00-\u9FA5]’)
8
9 print (‘input string: ‘, str\u test)
10 \findall get all matching characters in the string
11 num_list = num_regex.findall(str_test)
12 print (‘number contained: ‘, num\u list)
13 zimu_list = zimu_regex.findall(str_test)
14 print (‘included letters: ‘, zimu_list)
15 hanzi_list = hanzi_regex.findall(str_test)
16 print (‘Chinese characters included: ‘, hanzi_list)
Copy code
#Sheep door problem
Copy code
1 import random as r
2
3 \
4 total=1000000 #1000,1W,10W,100W
5 \change and no change winning times
6 win1=0
7 win2=0
8
9 for i in range(total):
10 \
11 man=r.randint(1,3)
12 car=r.randint(1,3)
13 \1\result: at the beginning, it was the door, not replaced +1
14 \1\1 otherwise, it will be sheep gate at the beginning, and +1
15 if man==car:
16 win1+=1
17 else:
18 win2+=1
10 nochange=nochange+1
11 else:
12 change=change+1
13 print (“the probability of getting a car without changing the group selection is {:.2f}”.Format (nochange/x))
14
15 print (“the probability of getting a car by changing the group selection is {:.2f}”.Format (change/x))