智一面的面试题提供python的测试题
使用地址:http://www.gtalent.cn/exam/interview?token=52cf92de494f4a8b6165d817a7279966
下面是大乐透模拟中奖的代码,同学们可以自己试试。
已知问题:
1.手动输入竞猜的数字没有做范围判断和类型判断,
2.五等奖中奖判断只做了一种,
3.只做了中奖输出,导致三四等奖的输出较混乱,
有兴趣的同学可以根据以上三个问题完善一下该代码。
小白一个,刚把函数和类学完,有什么更好的方法也请大家指点一下!谢谢!!!!
- from random import randint
- caipiao = []
- i = 1
- # 随机生成不重复的大乐透数字
- while i <= 1000:
- a = randint(1,35)
- b = randint(1,35)
- while True:
- if b == a:
- b = randint(1,35)
- else:
- break
- c = randint(1,35)
- while True:
- if c == a:
- c = randint(1,35)
- elif c == b:
- c = randint(1,35)
- else:
- break
- d = randint(1,35)
- while True:
- if d == a:
- d = randint(1,35)
- elif d == b:
- d = randint(1,35)
- elif d == c:
- d = randint(1,35)
- else:
- break
- e = randint(1,35)
- while True:
- if e == a:
- e = randint(1,35)
- elif e == b:
- e = randint(1,35)
- elif e == c:
- e = randint(1,35)
- elif e == d:
- e = randint(1,35)
- else:
- break
- f = randint(1,16)
- g = randint(1,16)
- while True:
- if g == f:
- g = randint(1,16)
- else:
- break
- # 用字符串输出大乐透号码
- caipiao_d = []
- caipiao_d.append(str(a))
- caipiao_d.append(str(b))
- caipiao_d.append(str(c))
- caipiao_d.append(str(d))
- caipiao_d.append(str(e))
- caipiao_d.append(str(f))
- caipiao_d.append(str(g))
- caipiao.append(caipiao_d)
- i += 1
- # 手动输入要竞猜的数字
- aa = str(input('请输入第1位数(1-35):'))
- bb = str(input('请输入第2位数(1-35):'))
- cc = str(input('请输入第3位数(1-35):'))
- dd = str(input('请输入第4位数(1-35):'))
- ee = str(input('请输入第5位数(1-35):'))
- ff = str(input('请输入第6位数(1-16):'))
- gg = str(input('请输入第7位数(1-16):'))
- my_cai = [aa,bb,cc,dd,ee,ff]
- # 判断是否中奖
- for caips in caipiao:
- my_c_z = []
- for caip in caips[:5]:
- if caip in my_cai[:5]:
- my_c_z.append(caip)
- for caip in caips[-2:]:
- if caip in my_cai[-2:]:
- my_c_z.append(caip)
- aa = len(my_c_z)
- # 判断中奖的等级
- if aa == 3:
- print(caips)
- print('五等奖')
- print(my_c_z)
- print('您的中奖号码为:')
- print(my_cai)
- print('\n\n')
- elif aa == 4:
- print(caips)
- print('四等奖')
- print(my_c_z)
- print('您的中奖号码为:')
- print(my_cai)
- print('\n\n')
- elif aa == 5:
- print(caips)
- print('三等奖')
- print(my_c_z)
- print('您的中奖号码为:')
- print(my_cai)
- print('\n\n')
- elif aa == 6:
- print(caips)
- print('二等奖')
- print(my_c_z)
- print('您的中奖号码为:')
- print(my_cai)
- print('\n\n')
- elif aa == 7:
- print(caips)
- print('一等奖')
- print(my_c_z)
- print('您的中奖号码为:')
- print(my_cai)
- print('\n\n')
python技术交流群:941108876
智一面的面试题提供python的测试题
http://www.gtalent.cn/exam/interview?token=e76073b0b31097ed0f2dbd76d03d2730
智一面的面试题提供python的测试题
http://www.gtalent.cn/exam/interview?token=e76073b0b31097ed0f2dbd76d03d2730