Common standard library random, python introductory tutorial 5 or 6 questions a day | Python skill tree

Dream eraser 2021-10-29 06:24:10
common standard library random python

This blog is mainly about https://bbs.csdn.net/skill/python Supplementary questions for the channel exercise module , It is tentatively provided every day 5 or 6 Road test questions , There may be more in the back ~.

This blog is right 【 Advanced Grammar 】→**【 Common standard library 】** Make a question .

The following questions , The default will be the correct answer , Place in options A Location

Knowledge point :python random library

The first 1 topic :

questions :1 star
stem ( Problem description ):
Which of the following options can be used in 1~100 Random selection in 10 A digital

Options A:

import random
for i in range(1, 6):
rand_num = random.randint(1, 100)
print(rand_num)

Options B:

import random
for i in range(1, 6):
rand_num = random.random(1, 100)
print(rand_num)

Options C:

import random
for i in range(1, 6):
rand_num = random.sample(1, 100)
print(rand_num)

Options D:

import random
for i in range(1, 6):
rand_num = random.randint(1, 101)
print(rand_num)

right key :A

The first 2 topic :

questions :1 star
stem ( Problem description ):
Programming , Randomly generate... For users in the program 6 Digit SMS verification code , Include capital letters .

Options A:

import random
password = []
for i in range(3):
num = random.randint(0, 9)
password.append(str(num))
char_num = random.randint(65, 90)
password.append(chr(char_num))
print("".join(password))

Options B:

import random
password = []
for i in range(6):
num = random.randint(0, 9)
password.append(str(num))
char_num = random.randint(65, 90)
password.append(chr(char_num))
print("".join(password))

Options C:

import random
password = []
for i in range(3):
num = random.randint(0, 9)
password.append(str(num))
char_num = random.randint(97,122)
password.append(chr(char_num))
print("".join(password))

Options D:

import random
password = []
for i in range(3):
num = random.randint(0, 9)
password.append(str(num))
char_num = random.randint(97,122)
password.append(chr(num ))
print("".join(password))

right key :A

The first 3 topic :

questions :2 star
stem ( Problem description ):
Crawler code writing , Will randomly get the user agent value , namely User-Agent, Write function , Achieve random access from the list User-Agent.

Options A:

import random
def get_headers():
uas = [
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)",
"Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)",
"Baiduspider-image+(+http://www.baidu.com/search/spider.htm)",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36",
]
ua = random.choice(uas)
headers = {

"user-agent": ua
}
return headers
if __name__ == '__main__':
print(get_headers())

Options B:

import random
def get_headers():
uas = [
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)",
"Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)",
"Baiduspider-image+(+http://www.baidu.com/search/spider.htm)",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (compatible; Googlebot-Image/1.0; +http://www.google.com/bot.html)",
"Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)",
"Sogou News Spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0);",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
"Sosospider+(+http://help.soso.com/webspider.htm)",
"Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)"
]
ua = random.random(uas)
headers = {

"user-agent": ua
}
return headers
if __name__ == '__main__':
print(get_headers())

Options C:

import random
def get_headers():
uas = [
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)",
"Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)",
"Baiduspider-image+(+http://www.baidu.com/search/spider.htm)",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (compatible; Googlebot-Image/1.0; +http://www.google.com/bot.html)",
"Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)",
"Sogou News Spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0);",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
"Sosospider+(+http://help.soso.com/webspider.htm)",
"Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)"
]
ua = random.sample(uas)
headers = {

"user-agent": ua
}
return headers
if __name__ == '__main__':
print(get_headers())

Options D:

import random
def get_headers():
uas = [
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)",
"Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)",
"Baiduspider-image+(+http://www.baidu.com/search/spider.htm)",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (compatible; Googlebot-Image/1.0; +http://www.google.com/bot.html)",
"Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)",
"Sogou News Spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0);",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
"Sosospider+(+http://help.soso.com/webspider.htm)",
"Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)"
]
ua = random.shuffle(uas)
headers = {

"user-agent": ua
}
return headers
if __name__ == '__main__':
print(get_headers())

right key :A

The first 4 topic :

questions :2 star
stem ( Problem description ):
stay 1000 Inside , Random access 6 It's an integer , It is required that the numbers do not repeat each other .

Options A:

from random import sample
ret = sample(range(1000), 6)
print(ret)

Options B:

from random import sample
ret = random.sample(range(1000), 6)
print(ret)

Options C:

import random
ret = random.shuffle(range(1000), 6)
print(ret)

Options D:

import random
for i in range(1, 6):
rand_num = random.randint(1, 1000)
print(rand_num)

right key :A

The first 5 topic :

questions :3 star
stem ( Problem description ):
Randomly generated by 1 and 0 A list of components ( The length requirement is 20), among 0 You can't have more than 5 individual .

Options A:

import random
zero_max = 5
my_list = [1] * 20
zero_list = random.randint(0, zero_max)
zero_pos = random.sample(range(20), zero_list)
for pos in zero_pos:
my_list[pos] = 0
print(my_list)

Options B:

import random
zero_max = 5
my_list = [1] * 20
zero_list = random.randint(0, zero_max)
zero_pos = random.sample(range(10), zero_list)
for pos in zero_pos:
my_list[pos] = 0
print(my_list)

Options C:

import random
zero_max = 5
my_list = [0] * 20
zero_list = random.randint(0, zero_max)
zero_pos = random.sample(range(10), zero_list)
for pos in zero_pos:
my_list[pos] = 0
print(my_list)

Options D:

import random
zero_max = 5
my_list = [0] * 20
zero_list = random.randint(0, zero_max)
zero_pos = random.sample(range(10), zero_list)
for pos in zero_list:
my_list[pos] = 0
print(my_list)

right key :A

The address of the test question warehouse is as follows :

https://codechina.csdn.net/hihell/question

版权声明
本文为[Dream eraser]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/10/20211013181453108o.html

  1. L'application de Seed en python
  2. Python functional programming series 008: Testability
  3. [must see for getting started with Python] the difference and connection between cookie and session in Python!
  4. Python Xiaobai from scratch pyqt5 project actual combat (4) basic controls
  5. Python Xiaobai starts the pyqt5 project from scratch (3) connection between signal and slot
  6. Echarts ne peut pas afficher le HTML en PDF en utilisant le pdfkit de Python
  7. 一只Python 小white 的日常提问(づ ●─● )づ
  8. 2021 tutoriel complet d'automatisation des tests d'interface python [matériel d'apprentissage joint]
  9. Décrivez ce que les connaissances pertinentes jouent dans votre travail en utilisant arduino ou Python, y compris les bibliothèques pertinentes, en conjonction avec votre travail quotidien.
  10. Une question quotidienne d'un petit morceau de Python (づ● - ●)
  11. Python中字典问题请求解惑
  12. 一只Python 小white 的日常提問(づ ●─● )づ
  13. 在python中的问题,请问如何解决
  14. Only 10 questions are needed to easily master Matplotlib graphics processing | Python skill tree
  15. 在python中的問題,請問如何解决
  16. Comment résoudre le problème en python
  17. Demande de résolution de problèmes de dictionnaire en python
  18. 使用python,在一个命名为.txt文本文档写入n m乘法表。
  19. En utilisant Python, écrivez une table de multiplication n m dans un document texte nommé.txt.
  20. 使用python,在一個命名為.txt文本文檔寫入n m乘法錶。
  21. Python,前缀后缀相同时合并
  22. 关于#python#的问题:python
  23. 關於#python#的問題:python
  24. Python,前綴後綴相同時合並
  25. Questions sur # # Python #: Python
  26. Python, préfixe et suffixe combinés en même temps
  27. python manage.py shell无法运行,
  28. python manage.py shell無法運行,
  29. Le shell Python manage.py ne fonctionne pas,
  30. python中使用vscode Import 'matplotlib.pyplot' could not be resolved from source 问题
  31. [Chapter 11 of the full version] Python advanced crawler practice - system master Po anti climbing skills challenge high salary
  32. L'utilisation de vscode Import 'matplotlib.pyplot' en python ne peut pas être résolue à partir du problème source
  33. Python fusionne les deux listes et supprime les éléments dupliqués lors de la fusion
  34. [JS Reverse AES Reverse Encryption] python crawler combat, les jours sont de plus en plus décisifs
  35. 30 jeux Python. Je peux jouer à la pêche au travail pendant une journée.
  36. J'a i collecté un nouveau hit de liste en python, donc c'est un secret que quelqu'un d'autre peut devenir un magnat des médias!
  37. J'a i utilisé Python pour ramper à travers 5000 belles photos de papier peint, un jour oublié Premier amour!
  38. [Python planting system] the best green plant for your girlfriend. Girls love it when they see it! Attachment: should be able to feed - right??!
  39. [Python love guide] two small programs for sweetness burst table are released! Afraid you can't find someone?
  40. J'ai utilisé Python pour ramper 1000 lettres d'amour pour aider mon colocataire à exprimer les fleurs de classe, mais les inverser et les inverser... C'est le secret ultime des fleurs de classe!
  41. J'ai utilisé Python pour me connecter à la plus grande plate - forme de jeu au monde, et à quel point le cryptage steam est intelligent [code source inclus]
  42. python中列表转为矩阵后无法进行矩阵的乘法运算
  43. Python crawler Development and Learning full tutoriel 2nd Edition, banggan 100000 words [recommended Collection]
  44. Python crawler haut de gamme: microstore confus anti - décryptage
  45. La multiplication de la matrice ne peut pas être effectuée lorsque la liste est convertie en matrice en python
  46. Introduction to operators in python (Part 1)
  47. Are the dictionaries in Python ordered
  48. Introduction to dictionaries in Python
  49. List introduction in Python
  50. pandas比较两个dataframe特定数据列的数值是否相同并给出差值:使用np.where函数
  51. Python使用matplotlib绘制透明背景的可视化图像并保存透明背景的可视化结果(transparent background)
  52. Python self study notes -- basic grammar
  53. Python utilise matplotlib pour dessiner une image visuelle de l'arrière - plan transparent et enregistrer les résultats visuels de l'arrière - plan transparent
  54. Pandas compare les valeurs de deux colonnes de données spécifiques à dataframe et donne des valeurs de voyage: en utilisant la fonction np.where
  55. Comment configurer une application ASGI Django avec Postgres, nginx et uvicorn sur Ubuntu 20.04
  56. What are the advantages of Python and how to get started quickly
  57. Python self study notes -- basic data types
  58. Python code reading (Chapter 14): List Union
  59. Analyse statistique de la fonction de données des essais aléatoires Python
  60. Alien invasion project in Python application -- Aliens (Part 2)