- 博客(29)
- 收藏
- 关注
原创 计算输入数字的算数平均数、方差和中位数
#计算输入数字的算数平均数、方差和中位数def getNum(): nums =[] iNumStr = input("请输入数字(回车退出):") while iNumStr !='': nums.append(eval(iNumStr)) iNumStr = input("请输入数字(回车退出):") return numsdef mean(numbers): s=0.0 for num in numbers: .
2021-11-05 09:45:58
647
2
原创 经典汉诺塔
#汉诺塔steps = 0def hanoi(src, des, mid, n): global steps if n == 1: steps += 1 print("[STEP{:>4}] {}->{}".format(steps, src, des)) else: hanoi(src, mid, des, n-1) steps += 1 print("[STEP{:>4}] {.
2021-11-04 08:52:55
119
原创 求输入数字的乘积
#输入若干个数字,求它们的乘积def cmul(a,*b): m = a for i in b: m = m*i return mprint(eval("cmul({})".format(input())))
2021-11-03 19:08:35
1757
1
原创 绘制科赫雪花
#科赫雪花import turtledef koch(size,n): if n == 0: turtle.fd(size) else: for angle in [0,60,-120,60]: turtle.left(angle) koch(size/3,n-1)def main(): turtle.setup(600,600) turtle.penup() turtle.got.
2021-11-03 17:13:58
145
原创 用七段数码管绘制系统当前日期,并用不同颜色显示年月日
#七段数码管-系统时间import turtle,timedef drawGap(): turtle.penup() turtle.fd(5)def drawLine(draw): drawGap() turtle.pendown() if draw else turtle.penup() turtle.fd(40) drawGap() turtle.right(90)def drawDigit(digit): drawLine(Tr.
2021-11-03 15:11:42
1059
原创 如何用七段数码管绘制某一个特定时间?
#七段数码管import turtledef drawLine(draw): turtle.pendown() if draw else turtle.penup() turtle.fd(40) turtle.right(90)def drawDigit(digit): drawLine(True) if digit in [2,3,4,5,6,8,9] else drawLine(False) drawLine(True) if digit in [0,1,.
2021-11-03 14:30:27
115
原创 用户登录的三次机会
#用户登录的三次机会count=1name=input()mima=input()while count<=3: if name=="kate"and mima=="666666": print("登录成功") break else: count=count+1while count==4: print("3次用户名或者密码均有误!退出程序。") break...
2021-11-03 09:46:29
208
原创 计算水仙花数,不显示最后一个逗号
#计算水仙花数a=0for i in range(100,999): a=str(i) if eval(a[0])**3+eval(a[1])**3+eval(a[2])**3==i: print(a,","[:-1])
2021-11-03 08:58:46
901
原创 计算整数加减和
#计算整数的加减和a=0for i in range(967): if i%2==1: a=a+i else: a=a-iprint(a)
2021-11-02 21:22:49
96
原创 种子数是123,如何用蒙特卡罗方法计算圆周率
#pi.pyfrom random import random,seedDARTS=eval(input())seed(123)hits=0.0for i in range (DARTS): x,y=random(),random() dist=pow(x**2+y**2,0.5) if dist<=1.0: hits=hits+1pi=4*(hits/DARTS)print("{:.6f}".format(pi))
2021-11-02 21:06:13
480
原创 你知道圆周率是如何计算的吗?这里利用蒙特卡罗方法进行了模拟,一起来看看
#pi.pyfrom random import randomfrom time import perf_counterDARTS=1000*1000*10hits=0.0start=perf_counter()for i in range (1,DARTS+1): x,y=random(),random() dist=pow(x**2+y**2,0.5) if dist<=1.0: hits=hits+1pi=4*(hits/DARTS)pr.
2021-11-02 20:31:27
104
原创 如何通过输入身高、体重,输出国标和国内的身体质量指数的所属等级,你,超重了吗?
#BMI2.pyheight,weight=eval(input("请输入身高(米)和体重\(公斤)[逗号隔开]:"))bmi=weight/pow(height,2)print("BMI数值为:{:.2f}".format(bmi))who,nat= "",""if bmi<18.5: who,nat="偏瘦","偏瘦"elif 18.5<=bmi<24: who,nat="正常","正常"elif 24<=bmi<25: who,na.
2021-11-02 14:20:33
1553
1
原创 2021-08-09
#天天向上的力量练习题def dayup(dayfactor): dayup=1.0 for i in range (365): if i %7in[6,0]: dayup=dayup*(1-0.01) else: dayup=dayup*(1+dayfactor) return dayupdayfactor=0.001while(dayup(dayfactor)<37.78):
2021-08-09 13:19:39
76
原创 2021-08-09
#星号三角形N=eval(input())n=int((N+1)/2)m=1for i in range (n): if m<2*n: M="*"*m print(str(M).center(N)) m=m+2
2021-08-09 13:16:50
57
原创 2021-08-09
#刷新的进度条import timescale=50print("执行开始".center(scale//2,"-"))start=time.perf_counter()for i in range(scale+1): a="*"*i b="."*(scale-i) c=(i/scale)*100 dur=time.perf_counter()-start print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,
2021-08-09 12:55:13
79
原创 2021-07-24
如何绘制玫瑰花送给男/女朋友import turtle# 设置初始位置turtle.penup()turtle.left(90)turtle.fd(200)turtle.pendown()turtle.right(90)# 花蕊turtle.fillcolor("red")turtle.begin_fill()turtle.circle(10,180)turtle.circle(25,110)turtle.left(50)turtle.circle(60,45)turtle.c
2021-07-24 16:33:04
63
原创 2021-07-24
#绘制八角图形import turtle as tt.pensize(2)for i in range(8):t.fd(150)t.left(135)
2021-07-24 16:10:19
65
原创 2021-07-24
#绘制八边形import turtle as tt.pensize(2)for i in range(8):t.fd(100)t.left(45)
2021-07-24 16:09:38
55
原创 2021-07-24
#绘制风轮绘制import turtle as tt.pensize(4)t.pencolor(“black”)t.left(135)for i in range (4):t.fd(120)t.left(90)t.circle(120,45)t.left(90)t.fd(120)t.right(135)t.done()
2021-07-24 15:52:35
68
原创 2021-07-24
#绘制叠九边形import turtle as tt.pensize(6)t.pencolor(“black”)for i in range(9):t.fd(120)t.left(80)t.done()
2021-07-24 15:42:15
57
原创 2021-07-24
#绘制六边形import turtle as tt.pensize(6)t.pencolor(“black”)for i in range(6):t.fd(120)t.left(60)t.done()
2021-07-24 15:36:34
47
原创 2021-07-24
#绘制正方形import turtle as tt.setup(650,350)t.pensize(6)t.pencolor(“black”)for i in range(4):t.fd(150)t.left(90)t.done()
2021-07-24 15:31:03
45
原创 2021-07-24
#绘制蟒蛇import turtle as tt.setup(650,350,200,200)t.penup()t.fd(-250)t.pendown()t.pensize(25)t.pencolor(“purple”)t.seth(-40)for i in range (4):t.circle(40,80)t.circle(-40,80)t.circle(40,80/2)t.fd(40)t.circle(16,180)t.fd(40*2/3)t.done()...
2021-07-24 15:13:16
59
原创 2021-07-23
摄氏度华氏度转换2temp = input()if temp[-1] in [‘F’,‘f’]:C = (eval(temp[0:-1])-32)/1.8print ("{:.2f}C".format©)elif temp[-1]in[‘C’,“c”]:F = 1.8*eval(temp[0:-1]) +32print ("{:.2f}F".format(F))else:print (“输入格式错误”)...
2021-07-23 14:24:20
51
原创 2021-07-23
摄氏度华氏度转换te=input ()if te[0] in [“F”]:C = (eval(te[1:])-32)/1.8print (“C{:.2f}”.format©)elif te[0]in[“C”]:F = 1.8*eval(te[1:]) +32print (“F{:.2f}”.format(F))else:print (“输入错误”)
2021-07-23 14:23:00
52
原创 2021-07-23
《美元与人民币转换》mon = input()if mon[0:3]==“RMB”: U = eval(mon[3:])/6.78 print(“USD{:.2f}”.format(U))elif mon[0:3]in[“USD”]: R = 6.78*eval(mon[3:]) print(“RMB{:.2f}”.format®)
2021-07-23 14:18:14
74
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人