实战01(大乐透号码生成器)
1 from random import sample 2 def number(): 3 front = sample([str(i) for i in range(1,36)],5) 4 back = sample([str(i) for i in range(1,13)],2) 5 space = [" "*6] 6 group = front + space + back 7 for i in group: 8 print(i.zfill(2),end=" ") 9 print("大乐透号码生成器") 10 while True: 11 amount = int(input("请输入要生成的大乐透号码注数:")) 12 for i in range(amount): 13 number() 14 print("") 15 print("")
实战02(春节集五福)
1 import random 2 3 class Number: 4 countFuNum_0 = [] 5 countFuNum_1 = [] 6 countFuNum_2 = [] 7 countFuNum_3 = [] 8 countFuNum_4 = [] 9 def __init__(self): 10 self.info1 = '开始集福了!\n 按下<Enter>键获取五福' 11 self.info2 = "当前拥有的福:" 12 self.info3 = "获取到:" 13 14 def fu(self, fuindex): 15 16 self.fuindex = fuindex 17 if self.fuindex == 0: 18 Number.countFuNum_0.append(self.fuindex) 19 print("和谐福") 20 if self.fuindex == 1: 21 print("富强福") 22 Number.countFuNum_1.append(self.fuindex) 23 if self.fuindex == 2: 24 Number.countFuNum_2.append(self.fuindex) 25 print("爱国福") 26 if self.fuindex == 3: 27 Number.countFuNum_3.append(self.fuindex) 28 print("友善福") 29 if self.fuindex == 4: 30 Number.countFuNum_4.append(self.fuindex) 31 print("敬业福") 32 print("和谐福: %d\t 富强福: %d\t 爱国福: %d\t 友善福: %d\t 敬业福: %d\t" % (len(Number.countFuNum_0),len(Number.countFuNum_1),len(Number.countFuNum_2),len(Number.countFuNum_3),len(Number.countFuNum_4))) 33 34 35 wufu = Number() 36 print(type(random.randint(0, 4))) 37 print(wufu.info1 + '\n') 38 39 40 wufuNum = input("") 41 if wufuNum == '': 42 for i in range(0,3): 43 print(wufu.info3) # "获取到:" 44 wufu.fu(int(random.randint(0, 4)))
实战04(计算个人所得税)
1 s = float(input("请输入月收入:")) 2 if s <0: 3 print("error") 4 else: # 根据不同范围逐级判断即可 5 salary = s - 5000 6 if salary <=3000: 7 fee, num = 3,0 8 elif 3000 < salary <= 12000: 9 fee, num = 10, 210 10 elif 12000 < salary <= 25000: 11 fee, num = 20, 1410 12 elif 25000 < salary <= 35000: 13 fee, num = 25, 2660 14 elif 35000 < salary <= 55000: 15 fee, num = 30, 4410 16 elif 55000 < salary <= 80000: 17 fee, num = 35, 7160 18 elif 80000 < salary : 19 fee, num = 45, 15160 20 tax = salary * fee / 100 - num 21 print("应缴税款{:.2f}元,实发工资{:.2f}元。".format(tax,salary + 5000 - tax))
标签:实战,self,countFuNum,Number,fuindex,len,Python8,print From: https://www.cnblogs.com/ron312/p/16882319.html