Python实现自由爆率抽奖小程序

时间: 2023-07-11 admin IT培训

Python实现自由爆率抽奖小程序

Python实现自由爆率抽奖小程序

import random
def write(x,y):while 1 :a_ = input (f"请输入{x}星爆率(0-{y},并且是整数):")try :c_ = int (a_)except:print ("请输入正确数字!")else:c_ = int (a_)if c_ < 0 or c_ > int(y) or c_ % 1 != 0:print ("请输入正确数字!")else:return c_def random_1 ():random_list = list(range (10000))b =int (random.choice(random_list))if b<=a_5:return  "¥¥¥¥¥"elif a_5 < b <= a_5 + a_4:return "¥¥¥¥"elif a_5 + a_4 <= b < a_5 + a_4 + a_3:return "¥¥¥"elif a_5 + a_4 + a_3 <= b <a_5 + a_4 + a_3 + a_2:return  "¥¥"else:return  "¥"y = 10000
a_5 = (write(5,y))
y = y - a_5
a_4 = (write(4,y))
y = y - a_4
a_3 = (write(3,y))
y = y - a_3
a_2 = (write(2,y))
y = y - a_2
a_1 = ywhile 1 :b_5=0b_4=0b_3=0b_2=0b_1=0number = input("你要抽几次?请输入:")try:a = int(number)except:print("请输入正确数字!")else:a = int(number)if a <= 0:print ("请输入正确数字!")elif a >100000:print("数字太大!请不要超过100000")else:for i in range(a + 1):if i != 0:q = random_1()print(f"{i}. {q}")if q =="¥¥¥¥¥":b_5 += 1elif q =="¥¥¥¥":b_4 += 1elif q =="¥¥¥":b_3 += 1elif q =="¥¥":b_2 += 1else:b_1 +=1print (f"恭喜你获得5星:{b_5}个!")print(f"恭喜你获得4星:{b_4}个!")print(f"恭喜你获得3星:{b_3}个!")print(f"恭喜你获得2星:{b_2}个!")print(f"恭喜你获得1星:{b_1}个!")