Lv.1
无
在 【Python作品分享】2019CoronaVirus散点传播实验(覆盖优化版)【作品秀】 中回复
import math import turtle import random#准备 people_1 = False people_2 = True people_3 = True people_4 = True people_5 = True people_6 = True people_7 = True people_8 = True people_9 = True people_10 = True people_11 = True people_12 = True people_13 = True people_14 = True people_15 = True people_16 = True people_17 = True people_18 = True people_19 = True people_20 = True people_21 = True people_22 = True people_23 = True people_24 = True people_25 = True people_26 = True people_27 = True people_28 = True people_29 = True people_30 = True people_31 = True people_32 = True people_33 = True people_34 = True people_35 = True people_36 = True people_37 = True #每个人的初始健康状态
def distance(x1, y1, x2, y2):
return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) #↑两点间的距离公式 #↓对列表中感染者、幸存者的数量检测 def check(List): infect=0 alive=0 for i in List: if i: alive+=1 else: infect+=1 return alive,infect s = turtle.Screen() s.setup(700,700)#设置屏幕的大小 people1 = turtle.Pen() people2 = turtle.Pen() people3 = turtle.Pen() people4 = turtle.Pen() people5 = turtle.Pen() people6 = turtle.Pen() people7 = turtle.Pen() people8 = turtle.Pen() people9 = turtle.Pen() people10 = turtle.Pen() people11 = turtle.Pen() people12 = turtle.Pen() people13 = turtle.Pen() people14 = turtle.Pen() people15 = turtle.Pen() people16 = turtle.Pen() people17 = turtle.Pen() people18 = turtle.Pen() people19 = turtle.Pen() people20 = turtle.Pen() people21 = turtle.Pen() people22 = turtle.Pen() people23 = turtle.Pen() people24 = turtle.Pen() people25 = turtle.Pen() people26 = turtle.Pen() people27 = turtle.Pen() people28 = turtle.Pen() people29 = turtle.Pen() people30 = turtle.Pen() people31 = turtle.Pen() people32 = turtle.Pen() people33 = turtle.Pen() people34 = turtle.Pen() people35 = turtle.Pen() people36 = turtle.Pen() people37 = turtle.Pen()#37个人类 people1.penup() people2.penup() people3.penup() people4.penup() people5.penup() people6.penup() people7.penup() people8.penup() people9.penup() people10.penup() people11.penup() people12.penup() people13.penup() people14.penup() people15.penup() people16.penup() people17.penup() people18.penup() people19.penup() people20.penup() people21.penup() people22.penup() people23.penup() people24.penup() people25.penup() people26.penup() people27.penup() people28.penup() people29.penup() people30.penup() people31.penup() people32.penup() people33.penup() people34.penup() people35.penup() people36.penup() people37.penup()#让移动不留痕迹 people1.speed(0) people2.speed(0) people3.speed(0) people4.speed(0) people5.speed(0) people6.speed(0) people7.speed(0) people8.speed(0) people9.speed(0) people10.speed(0) people11.speed(0) people12.speed(0) people13.speed(0) people14.speed(0) people15.speed(0) people16.speed(0) people17.speed(0) people18.speed(0) people19.speed(0) people20.speed(0) people21.speed(0) people22.speed(0) people23.speed(0) people24.speed(0) people25.speed(0) people26.speed(0) people27.speed(0) people28.speed(0) people29.speed(0) people30.speed(0) people31.speed(0) people32.speed(0) people33.speed(0) people34.speed(0) people35.speed(0) people36.speed(0) people37.speed(0)#加速实验 people1.color('red', 'red') people2.color('blue', 'blue') people3.color('blue', 'blue') people4.color('blue', 'blue') people5.color('blue', 'blue') people6.color('blue', 'blue') people7.color('blue', 'blue') people8.color('blue', 'blue') people9.color('blue', 'blue') people10.color('blue', 'blue') people11.color('blue', 'blue') people12.color('blue', 'blue') people13.color('blue', 'blue') people14.color('blue', 'blue') people15.color('blue', 'blue') people16.color('blue', 'blue') people17.color('blue', 'blue') people18.color('blue', 'blue') people19.color('blue', 'blue') people20.color('blue', 'blue') people21.color('blue', 'blue') people22.color('blue', 'blue') people23.color('blue', 'blue') people24.color('blue', 'blue') people25.color('blue', 'blue') people26.color('blue', 'blue') people27.color('blue', 'blue') people28.color('blue', 'blue') people29.color('blue', 'blue') people30.color('blue', 'blue') people31.color('blue', 'blue') people32.color('blue', 'blue') people33.color('blue', 'blue') people34.color('blue', 'blue') people35.color('blue', 'blue') people36.color('blue', 'blue') people37.color('blue', 'blue')#初始颜色,people1是初始感染者,为红色;其余为蓝色 all_pen = [people1, people2, people3, people4, people5, people6, people7, people8, people9, people10, people11, people12, people13, people14, people15, people16, people17, people18, people19, people20, people21, people22, people23, people24, people25, people26, people27, people28, people29, people30, people31, people32, people33, people34, people35, people36, people37] people_health = [people_1, people_2, people_3, people_4, people_5, people_6, people_7, people_8, people_9, people_10, people_11, people_12, people_13, people_14, people_15, people_16, people_17, people_18, people_19, people_20, people_21, people_22, people_23, people_24, people_25, people_26, people_27, people_28, people_29, people_30, people_31, people_32, people_33, people_34, people_35, people_36, people_37] #将每个人及他们的健康状态存入列表 hospital = int(input('输入初始医疗资源数量')) hospital_reaction_time = int(input('输入医院反应时间')) people_speed = int(input('输入人口流动速度')) jishi = 1 infect_distance = int(input('输入最大传染距离')) cure_speed = int(input('输入一天治疗几名患者')) shengchanlv = int(input('输入医疗资源生产效率(几天一个)'))#输入参数 for i in all_pen: i.goto(random.uniform(-350, 350), random.uniform(-350,350))#初始位置
2020-05-07T21:08:12 点赞:0
在 【Python作品分享】2019CoronaVirus散点传播实验(覆盖优化版)【作品秀】 中回复
while True:
for i in all_pen:
i.setheading(random.uniform(0, 360))
i.forward(people_speed)#所有人移动
for i in all_pen:
if(i.xcor() > 350):
i.setx(350)
if(i.ycor() > 350):
i.sety(350)
if(i.xcor() < -350):
i.setx(-350)
if(i.ycor() < -350):
i.sety(-350)#将出界者拉回屏幕
for i inrange(len(all_pen)):
for j inrange(len(all_pen)):
if(distance(all_pen[i].xcor(), all_pen[i].ycor(), all_pen[j].xcor(), all_pen[j].ycor()) <= infect_distance)and(not people_health[i]ornot people_health[j]):
all_pen[i].color('red', 'red')
all_pen[j].color('red', 'red')
people_health[i] = False
people_health[j] = False#用穷举法对所有感染情况进行判断,更新感染者和被感染者的颜色
if jishi==hospital_reaction_time + 1:
print('医院已开始工作!')#医院反应后开始工作
if jishi > hospital_reaction_time:
for i inrange(cure_speed):
for j in people_health:
if hospital <= 0:
continue#医疗资源用完时无法工作
ifnot j:
people_health[people_health.index(j)]=True
hospital-=1
break#每天治疗 cure_speed 名感染者
for i inrange(len(all_pen)):
if people_health[i]:
all_pen[i].color('blue','blue')#更新治愈者的颜色
print('Day',jishi)
print('医疗资源还够',hospital,'人使用')
a,b=check(people_health)
print('幸存者有',a,'位','感染者有',b,'位')
print('幸存者占比为',str(round(a/37*100,3))+'%','感染者占比为',str(round(b/37*100,3))+'%')#数据报告
if a==0:
print('人类已被全部感染!')# 结果报告
break
if b==0:
print('人类已被全部治愈!')# 结果报告
break
jishi+=1#记录循环次数的变量值+1
if jishi%shengchanlv==0:
hospital+=1#每几天生产出一人份的医疗物资
2020-05-07T21:09:09 点赞:0
在 【Python作品分享】2019CoronaVirus散点传播实验(覆盖优化版)【作品秀】 中回复
https://shequ.cod喵/community/261580
2020-05-07T21:53:49 点赞:0
在 【Python作品分享】不是作业 中回复
水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水
2020-05-08T19:07:12 点赞:0
在 【Python作品分享】新的作品【求助帖】 中回复
水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水
2020-05-11T17:25:51 点赞:0
在 【Python作品分享】计算器【作品秀】 中回复
<pre class="language-python"><code>
import math import tkinter import easygui#准备 calculator=tkinter.Tk()#创建窗口 calculator.geometry('400x400')#设置大小 calculator.resizable(0,0)#不许拉动 calculator.title('计算器')#设置标题 content=tkinter.StringVar() LEDboard=tkinter.Label(calculator,textvariable=content,bg='#efefef',width=50,height=1)#假装是LED板 LEDboard.place(x=20,y=100)#放置LED板 def one(): if"="in content.get(): content.set('1') else: content.set(content.get()+'1') b1 = tkinter.Button(calculator,text='1',bg='white',width=5,height=2,command=one) b1.place(x=100,y=200)2020-05-18T22:41:04 点赞:0
在 【Python作品分享】计算器【作品秀】 中回复
<pre class="language-python"><code> def equal():
content.set(content.get()+'=') try: value=content.get( )+str(eval(content.get().replace("factorial",'math.factorial').replace('×','*').replace('÷','/') .replace('sqrt','math.sqrt').replace('^', '**').replace('π',str(math.pi)). replace('e',str(math.e)).replace('sinr','math.sin').replace('cosr','math.cos').replace('tanr','math.tan') .replace("sind","math.sin(math.radians").replace("cosd","math.cos(math.radians") .replace("tand","math.tan(math.radians").replace("asin",'math.asin').replace("acos",'math.acos') .replace("atan",'math.atan').replace('=',''))) if'.'==str(value)[-2]and'0'==str(value)[-1]: content.set(str(value).split('.0')[0]) else: content.set(value) except ZeroDivisionError: easygui.msgbox('不能除以零!') content.set('') except: easygui.msgbox('输入有误!') content.set('')
def chengfang(): if"="in content.get(): content.set('^') else: content.set(content.get()+'^') mi= tkinter.Button(calculator, text='^', bg='white', width=5, height=2, command=chengfang)#乘方运算 mi.place(x=300, y=200) def zuokuohao(): if"="in content.get(): content.set('(') else: content.set(content.get()+'(') leftkuohao= tkinter.Button(calculator, text='(', bg='white', width=5, height=2, command=zuokuohao) leftkuohao.place(x=250,y=300) def youkuohao(): if"="in content.get(): content.set(')') else: content.set(content.get()+')') rightkuohao= tkinter.Button(calculator, text=')', bg='white', width=5, height=2, command=youkuohao) rightkuohao.place(x=300,y=300) #两个括号 def backspace(): if"="in content.get(): content.set('') else: content.set(''.join(list(content.get()[0:len(content.get())-1]))) huishan=tkinter.Button(calculator, text=chr(9003), bg='white', width=5, height=2, command=backspace)#回删 huishan.place(x=300,y=350) def pai(): if"="in content.get(): content.set('π') else: content.set(content.get()+'π') yuanzhoulv=tkinter.Button(calculator, text='π', bg='white', width=5, height=2, command=pai)#圆周率 yuanzhoulv.place(x=50,y=200) def e(): if"="in content.get(): content.set('e') else: content.set(content.get()+'e') # e E=tkinter.Button(calculator, text='e', bg='white', width=5, height=2, command=e) E.place(x=50,y=250) # https://www.bilibili.com/video/BV1qx411R7TA/?spm_id_from=333.788.videocard.0
content.set('') C=tkinter.Button(calculator,text='C',bg='white',width=5,height=2,command=all_clear) C.place(x=0,y=200)#全部清空
try: content.set((str(eval(str(content.get()).replace('factorial','math.factorial').replace('×', '*').replace('÷', '/').replace('sqrt', 'math.sqrt').replace('^', '**').replace('π',str(math.pi)). replace('e',str(math.e)).replace('sinr','math.sin').replace('cosr','math.cos').replace('tanr','math.tan') .replace("sind","math.sin(math.radians").replace("cosd","math.cos(math.radians") .replace("tand","math.tan(math.radians").replace("asin",'math.asin').replace("acos",'math.acos') .replace("atan",'math.atan'))**2))) except OverflowError: easygui.msgbox('太大了!!!') content.set('') except: easygui.msgbox('输入有误!')
try: content.set('sqrt('+str(eval(str(content.get()).replace('factorial','math.factorial').replace('×', '*').replace('÷', '/').replace('sqrt','math.sqrt').replace('^', '**').replace('π',str(math.pi)) .replace('e',str(math.e)).replace('sinr','math.sin').replace('cosr','math.cos').replace('tanr','math.tan').replace("sind","math.sin(math.radians").replace("cosd","math.cos(math.radians") .replace("tand","math.tan(math.radians").replace("asin",'math.asin').replace("acos",'math.acos').replace("atan",'math.atan')))+")") except ValueError: easygui.msgbox('负数不能开平方根!') except: easygui.msgbox('输入有误!')
try: content.set(('factorial('+str((eval(content.get().replace('factorial','math.factorial').replace('×', '*').replace('sqrt','math.sqrt').replace('÷', '/').replace('^', '**').replace('π',str(math.pi)). replace('e',str(math.e)).replace('sinr','math.sin').replace('cosr','math.cos').replace('tanr','math.tan').replace("sind","math.sin(math.radians").replace("cosd","math.cos(math.radians") .replace("tand","math.tan(math.radians").replace("asin",'math.asin').replace("acos",'math.acos').replace("atan",'math.atan')))))+")") except ValueError: easygui.msgbox('只有整数能够阶乘!') except OverflowError: easygui.msgbox('太大了!!!') content.set('') except: easygui.msgbox('输入有误!')
2020-05-18T22:42:30 点赞:0
在 【Python作品分享】计算器【作品秀】 中回复
<pre class="language-python"><code>
2020-05-18T22:43:44 点赞:0
在 【Python作品分享】520祝福【作业帖】 中回复
这段文字并非我的原创,摘自
https://www.bilibili.com/video/BV1LZ4y1p7YP的其中一个评论并加以修改
2020-05-20T22:49:29 点赞:1