追踪(最近一次通话): 文件“C:\ Users \ Mitch \ Documents \ lab3.py”,第18行,in 主要() 在主文件中输入文件“C:\ Users \ Mitch \ Documents \ lab3.py”,第15行 finddiscount(数量) 在finddiscount中输入文件“C:\ Users \ Mitch \ Documents \ lab3.py”,第2行 如果数量> = 1且数量< = 9: NameError:未定义全局名称“数量”
def finddiscount(discount):
if quantity >= 1 and quantity <= 9:
discount = "0%"
elif quantity >= 10 and quantity <= 19:
discount = "20%"
elif quantity >= 20 and quantity <= 49:
discount = "30%"
elif quantity >= 50 and quantity <= 99:
discount = "40%"
elif quantity >= 100:
discount = "50%"
print (discount)
def main():
quantity = int(input("How many packages where purchased?"))
finddiscount(quantity)
price = float(input("How much is each item?"))
return
main()
答案 0 :(得分:2)
尝试
def finddiscount(quantity): # not discount!