python - 将字典中的单个值添加到空字典中
问题描述
Products = {
"BUTTER": (4.50,False),
"BREAD": (2.70,False),
"BUTTON MUSHROOMS": (1.15,False),
"BAKING BEAN": (1.35,True),
"CEREAL": (7.00,True),
"CRACKERS": (3.10,False),
"EGGS": (3.40,False),
"MILK": (2.30,True),
"TOMATO": (1.45,True),
}
print("Name".ljust(padding), f'{"Price":>12}', f'{"Membership Applicable":>25}')
for name, (price, val) in Products.items():
print(name.ljust(padding), f"{price:>10}",f"{str(val):>18}")
def addItem():
itemlist()
getselection = input(
"Enter an item from the list above that u would like to add to cart :"
)
quantity = int(input("Enter how many of this item u would like to add to cart: "))
if quantity < 0:
print("Invalid quantity input")
elif getselection.upper() in Products:
shoppingCart[getselection.upper()] = quantity
print("\n", quantity, "of", getselection, "has been added to cart !\n",)
else:
print("Item not found")
addItem()
你好 !我正在尝试将数量名称成员资格(真/假)和价格添加到我的空字典中,到目前为止我可以添加数量和名称,因为它们以输入的形式但是我知道如何从产品字典中获取固定值
解决方案
推荐阅读
- influxdb - write_points() Python 不为 InfluxDB 写入数据
- firebase - FIREBASE 警告:Firebase 错误。请确保您的 Firebase 名称拼写正确
- c - 为什么逻辑或导致此“-Wint-conversion”警告?
- python - 如何按自定义重叠时段对熊猫数据框进行分组?
- asp.net-core - 从 IdentityServer 5 中的 IdP EndSessionEndpoint 检索“sid”声明?
- go - 无法将 terraform variables.tf 文件读入 may go 程序
- javascript - 有没有办法将 css 应用于元素的一部分?
- javascript - 我不断收到错误:require is not defined
- google-chrome-theme - 有没有办法为操作系统中的明暗模式指定不同的 Chrome 主题颜色?
- c++ - 为什么 Visual Studio 只返回整数?