day06 作业
猜年龄游戏
'''
1. 给定年龄,用户可以猜三次年龄
2. 年龄猜对,让用户选择两次奖励
3. 用户选择两次奖励后可以退出
'''
import random
age = random.randint(18, 40) # 随机数字,范围18-40
count = 0
reward_dict = {
'0': '奥特曼',
'1': '钢铁侠',
'2': '《笨方法学python》',
'3': '泰国一日游',
'4': 'iphoneX',
'5': '娃娃',
'6': '阿拉丁',
'7': '特斯拉',
'8': '谢谢惠顾'
}
reward_cart = {} # 用户获得奖品放在这里
while count < 3:
count += 1
age_inp = input('请输入你的年龄:').strip()
if not age_inp.isdigit(): # 判断是否是数字
print('非法输入字符,请重新输入')
age_inp = int(age_inp)
# 删选年龄范围
if age_inp > 40 or age_inp < 18:
print('超出范围,请重新输入')
# 核心逻辑
if age_inp == age:
print('猜对了')
# 打印奖品
for i, j in reward_dict.items():
print(f'奖品编号:{i} {j}')
# 用户抽奖两次
for k in range(2):
reward_choice = input('请输入你想要的奖品').strip()
if reward_choice not in reward_dict: # 删选范围
print('没这么多奖品')
else:
reward_get = reward_dict[reward_choice]
print(f'恭喜获得奖品:{reward_get}')
if reward_get not in reward_cart:
reward_cart[reward_get] = 1
else:
reward_cart[reward_get] += 1
print(f'恭喜你获得以下奖品:{reward_cart}')
break
elif age_inp < age:
print('猜小了')
else:
print('猜大了')
continue
三级菜单
menu = {
'北京': {
'海淀': {
'五道口': {
'soho': {},
'网易': {},
'google': {}
},
'中关村': {
'爱奇艺': {},
'汽车之家': {},
'youku': {},
},
'上地': {
'百度': {},
},
},
'昌平': {
'沙河': {
'老男孩': {},
'北航': {},
},
'天通苑': {},
'回龙观': {},
},
'朝阳': {},
'东城': {},
},
'上海': {
'闵行': {
"人民广场": {
'炸鸡店': {}
}
},
'闸北': {
'火车战': {
'携程': {}
}
},
'浦东': {},
},
'山东': {},
}
# 直接来,一层层进入
tag = True
while tag:
menu1 = menu
for key in menu1:
print(key)
choice1 = input('第一层>>').strip()
if choice1 == 'b':
break
if choice1 == 'q':
tag = False
continue
if choice1 not in menu1:
continue
while tag:
menu2 = menu1[choice1]
for key in menu2:
print(key)
choice2 = input('第二层>>').strip()
if choice2 == 'b':
break
if choice2 == 'q':
tag = False
continue
if choice2 not in menu2:
continue
while tag:
menu3 = menu2[choice2]
for key in menu3:
print(key)
choice3 = input('第三层>>').strip()
if choice3 == 'b':
break
if choice3 == 'q':
tag = False
continue
if choice3 not in menu3:
continue
while tag:
menu4 = menu3[choice3]
for key in menu4:
print(key)
choice4 = input('第四层>>').strip()
if choice4 == 'b':
break
if choice4 == 'q':
tag = False
continue
if choice4 not in menu4:
continue
# 偷懒方法
menu1 = [menu]
while True:
if len(menu1) == 0:
break
current_menu = menu1[-1]
for key in current_menu:
print(key)
choice = input('请输入>>').strip()
if choice == 'q':
break
if choice == 'b':
menu1.pop(-1)
continue
menu1.append(current_menu[choice])
day06 作业的更多相关文章
- python day06 作业答案
1. count=1 while count<11: fen=input('请第{}个评委打分' .format( count)) if int(fen) >5 and int(fen) ...
- day06作业---字典循环
'''1.1使⽤循环打印以下效果: ***************''' for a in range(1,6): print(a*'*') '''1.2: ***** **** *** ** * ' ...
- day06作业
一.方法 1.方法是完成特定功能的代码块. 修饰符 返回值类型 方法类型(参数类型 参数名1,参数类型 参数名2,...){ 方法体语句: return返回值: } 修饰符:目前就用publi ...
- python 作业
Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...
- DSB
Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...
- 老男孩Python全栈第2期+课件笔记【高清完整92天整套视频教程】
点击了解更多Python课程>>> 老男孩Python全栈第2期+课件笔记[高清完整92天整套视频教程] 课程目录 ├─day01-python 全栈开发-基础篇 │ 01 pyth ...
- day05对象和类
day06作业: 第一题:分析以下需求,并用代码实现 手机类Phone 属性: 品牌brand 价格price 行为: 打电话call() 发短信sendMessage() 玩游戏playGame() ...
- day06 再谈编码 and 作业讲解
1. 小数据池,(其他语言又叫常量池) id() 查看变量的内存地址 is和== is 判断内存地址是否一致 == 判断内容是否一致 小数据池的作用: 为了快速的创建字符串对象, 可以减少内存的浪费 ...
- python开发学习-day06(模块拾忆、面向对象)
s12-20160130-day06 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
随机推荐
- WindowsServer2003中IIS支持php的配置
1.安装MySQL(没有特殊说明的就按照默认安装)选择 Custom 自定义安装点击"Change"更改 MySQL 安装目录(自定义)其他按照默认的下一步就可以 安装完成后会自动 ...
- SQL必知必会|SQL基础篇
了解SQL DBMS的前世今生 SQL是如何执行的 DDL语法 关于外键的性能问题? 是否使用外键确实会有一些争议.关于外键的使用: 首先,外键本身是为了实现强一致性,所以如果需要正确性>性能的 ...
- 线程休眠sleep
一.sleep的作用 sleep() 定义在Thread.java中.sleep() 的作用是让当前线程休眠,即当前线程会从“运行状态”进入到“休眠(阻塞)状态”.sleep()会指定休眠时间,线程休 ...
- luoguP3181 [HAOI2016]找相同字符
题意 考虑将\(s1\)和\(s2\)接在一起求出相同子串个数,再求出\(s1\)自己匹配的相同子串个数和\(s2\)自己匹配的相同子串个数减去即可. 如何求相同子串个数: 我们知道子串的集合即所有后 ...
- <Array> 277 243 244 245
277. Find the Celebrity knows(i, j): By comparing a pair(i, j), we are able to discard one of them 1 ...
- 洛谷P3157 [CQOI2011]动态逆序对
题目大意: 给定\(1\)到\(n\)的一个排列,按照给定顺序依次删除\(m\)个元素,计算每个元素删除之前整个序列的逆序对数量 基本套路:删边变加边 那么我们不就是求满足\(pos_i<pos ...
- SUDO_KILLER可以帮助你识别并利用错误的Sudo规则与配置
工具概述 SUDO_KILLER这款工具可以帮助我们通过多种渠道利用SUDO来在Linux环境下实现提权.该工具能够识别目标操作系统版本,并发现环境中sudo规则的错误配置.安全漏洞,以及不安全的代码 ...
- C++中enum(转载)
原文地址:http://www.cnblogs.com/ForFreeDom/archive/2012/03/22/2412055.html 1.为什么要用enum 写程序时,我们常常需要 ...
- keras和tensorflow搭建DNN、CNN、RNN手写数字识别
MNIST手写数字集 MNIST是一个由美国由美国邮政系统开发的手写数字识别数据集.手写内容是0~9,一共有60000个图片样本,我们可以到MNIST官网免费下载,总共4个.gz后缀的压缩文件,该文件 ...
- Shell基本运算符之算术、关系运算符
Shell 运算符 =============================摘自菜鸟教程================================= Shell和其他编程语言一样,支持多种运算 ...