python好玩的代码_分享几款由“Python”语言编写的“有趣、恶搞、好玩”的程序代码...

为提高大家对“Python”编程语言的学习兴趣,今天给大家分享几款有趣的Python程序代码,感兴趣的小伙伴可以跟着学习借鉴哦!

分享一:"啥是佩奇?"让Python语言告诉你

3737d57334ce330e5c3d1e65c1d79ff9.png

用Python代码创作一副佩奇:

1. # coding:utf-82. import turtle as t3.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.418. for i in range(120):19. if 0<=i<30 or 60<=i<90:20. a=a+0.0821. t.lt(3) #向左转3度22. t.fd(a) #向前走a的步长23. else:24. a=a-0.0825. 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.475. for i in range(60):76. if 0<=i<30 or 60<=i<90:77. a=a+0.0878. t.lt(3) #向左转3度79. t.fd(a) #向前走a的步长80. else:81. a=a-0.0882. 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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然,Python有很多有趣程序代码!以下是一些示例: 1. 猜数字游戏: ```python import random num = random.randint(1, 100) guess = int(input("猜一个1到100之间的数字:")) while guess != num: if guess < num: print("太小了!再试一次。") else: print("太大了!再试一次。") guess = int(input("猜一个1到100之间的数字:")) print("恭喜你,猜对了!") ``` 2. 文字冒险游戏: ```python def start_game(): print("欢迎来到文字冒险游戏!") name = input("请输入你的名字:") print("你好," + name + "!你的冒险开始了。") choice = input("你来到一个十字路口,你要往左走还是往右走?(左/右)") if choice == "左": print("你选择了往左走,你看到了一只大熊。游戏结束!") elif choice == "右": print("你选择了往右走,你看到了一座宝箱。你打开宝箱,发现里面有一把宝剑。恭喜你,你获得了胜利!") else: print("无效的选择,请重新开始游戏。") start_game() ``` 3. 斐波那契数列生成器: ```python def fibonacci(n): sequence = [0, 1] while len(sequence) < n: next_num = sequence[-1] + sequence[-2] sequence.append(next_num) return sequence num_terms = int(input("请输入要生成的斐波那契数列的项数:")) fib_sequence = fibonacci(num_terms) print(fib_sequence) ``` 这些只是一些简单的示例,Python的应用非常广泛,你可以根据自己的兴趣和创造力编写更多有趣程序代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值