我不确定如何解释这个问题,但我会尽我所能。 我试图在最后显示一个句子来显示用户对包的选择。但是,用户只能通过数字选择包...例如
(样本输出) 葡萄12美元 2.橘子13美元 3.柠檬$ 2
def load(packages)
packageDict = {"name" : package, "cost": costPrice}
packages.append(packageDict)
def calculate(packages)
packageSelect int(input("Select package"))
while packageSelect > 5 or PackageSelect <1:
print ("Invalid)
packageSelect int(input("Select package))
print("you have selected the"+ (package) + "package")
答案 0 :(得分:1)
一些建议:
def load(packages)
packageDict = {"name" : package, "cost": costPrice}
packages.append(packageDict)
def calculate(packages)
packageSelect int(input("Select package"))
while packageSelect > len(packages) or PackageSelect < 1:
print ("Invalid input, retry")
packageSelect = int(input("Select package"))
return packageSelect
packages = ['a', 'b', 'c']
package = calculate(packages)
print("you have selected the"+ packages[package - 1] + "package")