我在尝试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还很陌生,这是我必须学习的第一个实际类。感谢您的时间和提前答复