python怎么让用户输入字典_如何获取用户输入以引用Python字典

我在尝试Python作业时遇到了一点小麻烦。在作业中,我被要求为一家杂货店创建一个信贷计划。这是很简单的事情我只是在最后一部分遇到了麻烦。因此,我们需要采取3个用户输入来决定他们想购买的项目。有了这些输入,我需要将此人输入的内容转换为价格。另外,我一直在使用print('''''')来跳过行,我找到了几种方法来弥补这个问题,但不确定是否正确。在

到目前为止,我的任务是:prices = {}

aa = 5.

bb = 4.

cc = 10.

dd = 3.

ee = 5.

ff = 4.

prices[aa] = 'shrimp'

prices[bb] = 'groundbeef'

prices[cc] = 'tuna'

prices[dd] = 'sodapop'

prices[ee] = 'fruitplate'

prices[ff] = 'spicerack'

print("Hello and welcome to Lakeside Market:") #generic greeting

print('''''') #skip line

deposit = input("How much would you like to deposit into your account?") #asks for a amount to deposit

print('''''') #skip line

deposit = int(deposit) #makes deposit variable an integer # turns deposit into an integer

bonus = 10 #creates $10 bonus if $20+ is taken from input

accountbalance = deposit + bonus # will be used when the user has entered a correct deposit amount

if deposit < 20: #basic if/else statement. If you put less than 20 it will tell you

print("I'm sorry that doesn't meet the minimum requirement of $20")

exit()

else: #if 20+ is entered

print("Thank you, your funds have been deposited into your account.")

print('''''')

print("Your balance is $",accountbalance) #balance is printed with first-time bonus of 10 added

print('''''')

print("We offer: shrimp, groundbeef, tuna, sodapop, fruitplate and spicerack") # here are the different items that can be input

print("Please enter items as they appear above...") #item1 input

print('''''')

item1 = input("To begin, please enter an item name:") #item2 input

item2 = input("Now, add a second item:")

item3 = input("Finally, add your last item:") #item3 input

为了完成分配,我需要将用户输入的最后(item1,item2,item3)转换为prices指令中项目的实际价格。然后我将这些项目相加,并从accountbalance中减去该金额,这将给我一个新的账户总额。我知道这是非常基本的东西,但我对Python还很陌生,这是我必须学习的第一个实际类。感谢您的时间和提前答复

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值