Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Python actual combat project code exercises?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what are the Python practical project code exercises". In the daily operation, I believe that many people have doubts about the Python practical project code exercises. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the Python practical project code exercises?" Next, please follow the editor to study!

1. Grab Zhihu image with only 30 lines of code from selenium import webdriverimport timeimport urllib.requestdriver = webdriver.Chrome () driver.maximize_window () driver.get ("https://www.zhihu.com/question/29134042")i = 0while I < 10: driver.execute_script (" window.scrollTo (0, document.body.scrollHeight)) ") time.sleep (2) try: driver.find_element_by_css_selector ('button.QuestionMainAction'). Click () print (" page "+ str (I)) time.sleep (1) except: breakresult_raw = driver.page_sourcecontent_list = re.findall (" img src=\ "(. +?)\" Str (result_raw)) n = 0while n < len (content_list): I = time.time () local = (r "% s.jpg"% (I)) urllib.request.urlretrieve (content_list [n], local) print ("number:" + str (I)) n = n + 12. Listen to two chatbots chat with each other from time import sleepimport requestss = input ("ask the host to enter the topic:") while True: resp = requests.post ("http://www.tuling123.com/openapi/api",data={"key":"4fede3c4384846b9a7d0456a5e1e2943"," info ": s,}) resp = resp.json () sleep (1) print ('Little Fish:' Resp ['text']) s = resp [' text'] resp = requests.get ("http://api.qingyunke.com/api.php", {'key':' free', 'appid':0,' msg': 's}) resp.encoding = 'utf8' resp = resp.json () sleep (1) print (' Feifei:', resp ['content']) # there is also a small I robot that is said to have a high IQ. Use the crawler function to implement: import urllib.requestimport rewhile True: X = input ("master:") x = urllib.parse.quote (x) link = urllib.request.urlopen ("http://nlp.xiaoi.com/robot/webrobot?&callback=__webrobot_processMsg&data=%7B%22sessionId%22%3A%22ff725c236e5245a3ac825b2dd88a7501%22%2C%22robotId%22%3A%22webbot%22%2C%22userId%22%3A%227cd29df3450745fbbdcf1a462e6c58e6%22%2C%") 22body%22%3A%7B%22content%22%3A%22 "+ x +"% 22%7D%2C%22type%22%3A%22txt%22%7D ") html_doc = link.read () .decode () reply_list = re.findall (r'\" content\ ":\" (. +?)\ r\ n\ "' Html_doc) print ("Xiao I:" + reply_list [- 1]) 3. To analyze whether the author of Tang poetry is Li Bai or du Fu import jiebafrom nltk.classify import NaiveBayesClassifier#, we need to collect Li Bai's poems in advance and put them in the libai.txt text. Text1 = open (r "libai.txt", "rb"). Read () list1 = jieba.cut (text1) result1 = ".join (list1) # need to collect du Fu's poems in advance and put them in the dufu.txt text. Text2 = open (r "dufu.txt", "rb"). Read () list2 = jieba.cut (text2) result2 = ".join (list2) # data preparation libai = result1dufu = result2# feature extraction def word_feats (words): return dict ([(word, True) for word in words]) libai_features = [(word_feats (lb), 'lb') for lb in libai] dufu_features = [(word_feats (df)) 'df') for df in dufu] train_set = libai_features + dufu_features# training decision classifier = NaiveBayesClassifier.train (train_set) # Analytical Test sentence = input ("Please enter a poem you like:") print ("\ n") seg_list = jieba.cut (sentence) result1 = ".join (seg_list) words = result1.split (") # Statistical results lb = 0df = 0for word in words: classResult = classifier .purify (word_feats (word)) if classResult = 'lb': lb = lb + 1 if classResult =' df': df = df + rendering ratio x = float (str (float (lb) / len (words) y = float (str (float (df) / len (words)) print ('possibility of Li Bai:% .2f%'% (x * 100)) print ('possibility of du Fu Sex:% .2f%%'% (y * 100) 4. Random generation of lottery tickets 35 choose 7import randomtemp = [I + 1 for i in range (35)] random.shuffle (temp) I = 0list = [] while I < 7: list.append (temp [I]) I = I + 1list.sort () print ('0033 [0print 31mitt1m') print (* list [0:6], end= ") print (' 0tram33 [0Tracter34 [end=") print (list [- 1]) 5. Automatically write the review import randomimport xlrdExcelFile = xlrd.open_workbook (rasctest.xlsx') sheet = ExcelFile.sheet_by_name ('Sheet1') I = [] x = input ("Please enter specific events:") y = int (input ("number of words required by the teacher:") while len (str (I)) < y * 1.2: s = random.randint (1) 60) rows = sheet.row_values (s) i.append (* rows) print ("* 8 +" Review "+"\ n "+" teacher: ") print (" I shouldn't "+ str (x) +" ", * I) print (" excuse me again! ")''

The following is a sample draft:

Please enter a specific event: smoking

The number of words required by the teacher: 200

Review letter

Teacher:

I should not smoke. The school repeatedly emphasized the school rules and discipline and reminded the students not to violate the school rules. However, I did not take the words of the school and the teacher in mind, paid no attention to what the teacher said, and did not attach importance to the important matters promulgated by the school. It turned a deaf ear to it. At the same time, I sincerely hope that the teacher can continue to care about and support me, and deal with my problems as appropriate. No matter in the study or in other aspects, I will use the school rules to strictly require myself, I will seize this opportunity. However, facts have proved that it is not enough to invest passionately, work hard and study hard. We also need to have a clear political mind, a sense of overall interests and a sense of discipline, otherwise we will lose our way in learning and cause losses to the country and schools.

Please forgive the teacher again!

''

6. Screen recording camera, screen capture software from time import sleepfrom PIL import ImageGrabm = int (input ("Please enter a few minutes to capture the screen:) m = m * 60n = 1while n < m: sleep (0.02) im = ImageGrab.grab () local = (r"% s.jpg "% (n)) im.save (local, 'jpeg') n = n + 17. Make Gif motion picture from PIL import Imageim = Image.open ("1.jpg") images= [] images.append (Image.open ('2.jpg')) images.append (Image.open (' 3.jpg')) im.save ('gif.gif', save_all=True, append_images=images, loop=1, duration=1, comment=b "aaab so far, the study on" what are the code exercises of Python practical combat project "is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report