![[嗒啦啦2_经验+3]](https://img.tapimg.com/market/images/f2dbb0dbf9438e3a20cd14342d893191.gif)
自学两天python做的抽卡模拟器
2021/07/302366 浏览综合
能模拟抽出多少6x 能算2000次的平均值 代码如下 粘到记事本 后缀改成.py 然后下个python就能打开了![[嗒啦啦2_经验+3]](https://img.tapimg.com/market/images/f2dbb0dbf9438e3a20cd14342d893191.gif)
![[嗒啦啦2_经验+3]](https://img.tapimg.com/market/images/f2dbb0dbf9438e3a20cd14342d893191.gif)
文本框输入想抽几抽![[嗒啦啦2_哈哈]](https://img.tapimg.com/market/images/1bbca193685a619674d8260ad0ed7455.gif)
![[嗒啦啦2_哈哈]](https://img.tapimg.com/market/images/1bbca193685a619674d8260ad0ed7455.gif)
import tkinter
mainwin=tkinter.Tk()
mainwin.title('明日方舟抽卡模拟')
mainwin.geometry('720x480+360+240')
def comp1(n=0):#计算n次出的个数
from random import random
if n<=0:
return '请输入正数'
def p(i1):#概率修正
if i1>50:
return (i1-49)*0.02
else:
return 0.02
upCount=0
probCount=1
for i2 in range(1,n+1):
if random()<p(probCount):
upCount+=1
probCount=1
else:
probCount+=1
return upCount
def comp2(n=0):#计算2000次n抽出的平均个数
if n<=0:
return '请输入正数'
sum1=0
for i1 in range(2000):
sum1+=comp1(n)
return sum1/2000
tex1=tkinter.Entry(mainwin,bd=3)
def bott1():
tex1Content=int(tex1.get())
lab1=tkinter.Label(mainwin,text=comp1(tex1Content))
lab1.pack()
def bott2():
tex1Content=int(tex1.get())
lab1=tkinter.Label(mainwin,text=comp2(tex1Content))
lab1.pack()
bot1=tkinter.Button(mainwin,text='试试手',padx=24,pady=12,command=bott1)
bot2=tkinter.Button(mainwin,text='求期望',padx=24,pady=12,command=bott2)
tex1.pack()
bot1.pack()
bot2.pack()
mainwin.mainloop()