双色球选购作业答案(购物车答案在文章下方)
#!/usr/bin/env python # -*- coding:utf-8 -*- # @Author:薛定谔的猫 2019/5/6 13:42 def selectR(): SelectRed = [] for i in range(6): SelectedRedNum = len(SelectRed) for i in range(6 - SelectedRedNum): RedBall = input("请选择六个红球数字(1~32):") if RedBall.isdigit(): if int(RedBall) > 32 or int(RedBall) < 1: print("请输入1~32之间的数字(可包含1,32)") if int(RedBall) < 33 and int(RedBall) > 0: if int(RedBall) not in SelectRed: SelectRed.append(int(RedBall)) else: print("数字" + str(RedBall) + "已经被选过了,请不要重复选择") print("已选择的红球" + str(SelectRed)) else: print("请输入1~32之间的数字") return SelectRed def selectB(): SelectBlue = [] for i in range(2): SelectedBlueNum = len(SelectBlue) for i in range(2 - SelectedBlueNum): BlueBall = input("请选择2个蓝球数字(1~16):") if BlueBall.isdigit(): if int(BlueBall) > 16 or int(BlueBall) < 1: print("请输入1~16之间的数字(可包含1,16)") if int(BlueBall) < 17 and int(BlueBall) > 0: if int(BlueBall) not in SelectBlue: SelectBlue.append(int(BlueBall)) else: print("数字" + str(BlueBall) + "已经被选过了,请不要重复选择") print("已选择的蓝球" + str(SelectBlue)) else: print("请输入1~16之间的数字") return SelectBlue print("欢迎来到“薛定谔的猫”双色球系统") print("现在开始选择红球") SelectRed = selectR() print("现在开始选择篮球") SelectBlue = selectB() print("------------------------------") print("选号完成") print("您选择的红球为" + str(SelectRed)) print("您选择的蓝球为" + str(SelectBlue))
三级菜单作业答案
#!/usr/bin/env python # -*- coding:utf-8 -*- # @Author:薛定谔的猫 2019/5/6 14:40 menu = { '北京': { '海淀': { '五道口': { 'soho': {}, '网易': {}, 'google': {} }, '中关村': { '爱奇艺': {}, '汽车之家': {}, 'youku': {}, }, '上地': { '百度': {}, }, }, '昌平': { '沙河': { '老男孩': {}, '北航': {}, }, '天通苑': {}, '回龙观': {}, }, '朝阳': {}, '东城': {}, }, '上海': { '闵行': { "人民广场": { '炸鸡店': {} } }, '闸北': { '火车站': { '携程': {} } }, '浦东': {}, }, '山东': {}, } def sjcd(dic): while True: for k in dic: print(k) key = input('请输入指令,输入上面的菜单名称进入下级菜单,输入b返回上级,输入q退出:').strip() if key == 'b' or key == 'q': return key elif key in dic.keys() and dic[key]: ret = sjcd(dic[key]) if ret == 'q': return 'q' elif (not dic.get(key)) or (not dic[key]): continue sjcd(menu)
购物车答案请进微信交流群获取
微信群:
QQ群:
点击链接加入群聊【Python和极客技术】: