sairate 7df250638d chore: 添加项目基础结构和示例代码
- 创建 .idea 目录和相关配置文件,设置项目结构
- 添加多个课堂成果示例代码,涵盖不同主题和功能
- 创建和配置 .gitignore 文件,忽略特定文件和目录
2025-07-05 09:36:00 +08:00

42 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'''来拆盲盒吧
超市最近新推出了商品盲盒的活动顾客支付30元可以获得一次开盲盒的机会。顾客们都跃跃欲试想看看自己的手气。
盲盒中会随机出现三种商品你可能会买到价值远高于30的商品你也可能得到刚好30或者低于30的商品。快来试试自己的运气吧
提示如下:
1. 已知参与盲盒活动的商品及价格
2. 从中随机抽取三种商品并输出
3. 计算抽出的三种商品总价值
4. 输出“你的盲盒价值××元”'''
import random
shop = {
'防滑衣架1套':10, '湿巾1包':4, '中性笔1支':3, '牙膏1管':33,
'矿泉水1瓶':2, '洗洁精1瓶':7 , '苹果3斤':15, '蔓越莓曲奇1盒':7,
'泡椒凤爪1包':5, '鱿鱼丝1包':22
}
# 方法一:
goods = list(shop.keys())
my = random.sample(goods, 3)
print(my)
total= int(shop[my[0]]) + int(shop[my[1]]) + int(shop[my[2]])
print(f'您的盲盒价值{total}')
'''
# 方法二:
goods = list(shop.keys())
random.shuffle(goods)
my = []
for i in range(3):
my.append(goods[i])
print(my)
total= int(shop[my[0]]) + int(shop[my[1]]) + int(shop[my[2]])
print(f'您的盲盒价值{total}')
'''