作业题目:双色球选购

作业需求:

双色球(假设一共八个球,6个红球,球号1-32、2个蓝球,球号1-16)
确保用户不能重复选择,不能超出范围
用户输入有误时有相应的错误提示
最后展示用户选择的双色球的号码
效果图:双色球作业展示
升级需求:
  一个while循环

踩分点:

满分100分,按照实现的需求以及代码的规范程度来进行评分
  基本功能(85分)
  升级需求(5)
  代码简洁、规范(规范请参考python代码规范(10分)

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 # @Time    : 2019/10/27 8:53
 4 
 5 red_ball = []  # 空列表
 6 blue_ball = []
 7 count = 1  # 双色球开始计数
 8 print("----双色球选购,五百万大奖等你来中----")
 9 while count < 7:  # 6个红球
10     red_input = input("\033[31m[%d]select red ball:\033[0m" % count).strip()  # \033[31m \033[0m更改字体为红色
11     if red_input.isdigit():  # 判断数字
12         red_input = int(red_input)  # 转换
13         if red_input in red_ball:  # 判断重复
14             print("number", red_input, "is already exist in red ball list")
15         elif 0 < red_input < 33:  # 判断范围
16             red_ball.append(red_input)  # append 增
17             count += 1
18         else:
19             print("only can select n between 1-32")
20 count = 1  # 重置为1
21 while count < 3:
22     blue_input = input("\033[34m[%d]select blue ball:\033[0m" % count).strip()  # \033[34m \033[0m更改字体为蓝色
23     if blue_input.isdigit():
24         blue_input = int(blue_input)
25         if blue_input in blue_ball:
26             print("number", blue_input, "is already exist in red ball list")
27         elif 0 < blue_input < 17:
28             blue_ball.append(blue_input)
29             count += 1
30         else:
31             print("only can select n between 1-16")
32 else:
33     print("")  # 空出一行
34     print("\033[31mRed ball:\033[0m", red_ball)
35     print("\033[34mBlue ball:\033[0m", blue_ball)
36     print("祝你好运,欢迎下次再来.")  # sep="",解决换行不对齐,但是太长了放弃
双色球选购

猜你喜欢

转载自www.cnblogs.com/tu240302975/p/11746946.html