![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python代码
可乐加冰884
这个作者很懒,什么都没留下…
展开
-
Python-绘制花朵
import turtle as t t.penup() t.fd(-200) t.write("一朵小花\n", align="right", font=("楷体", 16, "bold")) def draw_leaf(): for i in range(2): for j in range(15): t.forward(5) t.right(6) t.right(90) t.goto(0,-1..转载 2022-05-24 15:24:15 · 2457 阅读 · 0 评论 -
Python-七段数码管的绘制
import turtle,datetime def drawLine(draw):#绘制单段数码管 turtle.pendown()if draw else turtle.penup() turtle.fd(40) turtle.right(90) def drawDigit(d):#根据数字绘制七段数码管 drawLine(True)if d in [2,3,4,5,6,8,9,]else drawLine(False) drawLine(True)if d .原创 2022-05-23 17:36:11 · 538 阅读 · 0 评论 -
4.6羊车门问题
有3扇关闭的门,一扇门后停着汽车,另外两扇门后是山羊,主持人知道每扇门后是什么。参赛者首先选择一扇门。在开启它之前,主持人会从另外两扇门中打开一扇门,露出门后的山羊。此时,允许参赛者更换自己的选择。请问,参赛者更换选择后,能否增加猜中汽车的机会? from random import* times = 10000 first_n=0#不改选择的次数 change_n=0#更改选择的次数 for i in range(times): car=randint(0,2) guess=randint(0,2原创 2022-04-18 11:59:01 · 1001 阅读 · 0 评论 -
4.5猜数字续(异常处理)
from random import * x=randint(0,100)#预设0-100的整数 n=0 while (1): try: print("请输入0-100的数字") while(1): m=eval(input()) if x<m: print("遗憾,太大了") n+=1 continue .原创 2022-04-18 11:17:53 · 1088 阅读 · 0 评论 -
最大公约数与最小公倍数计算
print("请输入两个整数:(英文逗号隔开)") x,m=map(int,(input().split(","))) if x>m: y=x x=m m=y p,c=x,m while m%x!=0: l=x x=m%x m=l print("最大公约数为:"+str(x)+"最小公倍数:"+str(p*c//x)) ...原创 2022-04-18 11:02:47 · 383 阅读 · 0 评论 -
统计字符串中不同字符个数
print("请输入一串字符") Letter=0 Number=0 Else=0 Space=0 x=input() for i in x: if 65<=ord(i)<=122: Letter+=1 elif 48<=ord(i)<=57: Number+=1 elif 32==ord(i): Space+=1 else: Else+=1 print("其中英文字符.原创 2022-04-17 16:09:48 · 327 阅读 · 0 评论 -
python-猜数字游戏(0-9)
from random import * x=randint(0,9)#预设0-9的整数 n=0 print("请输入0-9的数字") while(1): m=eval(input()) if x<m: print("遗憾,太大了") n+=1 continue if(x>m): print("遗憾,太小了") n+=1 continue else: .原创 2022-04-17 15:30:08 · 11420 阅读 · 2 评论 -
应用蒙特卡罗方法求解π
from random import random from math import sqrt import time darts=10000#抛点数 hits=0 t=time.perf_counter() for i in range(1,darts+1): x,y=random(),random() dist=sqrt(x**2+y**2) if dist<=1: hits+=1 pi=4*(hits/darts) print("π的值为:{:.5f}"...原创 2022-04-17 15:01:27 · 283 阅读 · 0 评论 -
入门:Python进度条
import time s=20 print("执行开始") t=time.perf_counter() for i in range (s+1): a='*'*i b='.'*(s-i) c=(i/s)*100 t-=time.perf_counter() print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,-t),end='') time.sleep(0.05) print("\n"+"执行结束".cen.原创 2022-04-07 23:15:12 · 504 阅读 · 0 评论