number_of_people = input("Enter number of people attending the picnic: ")
if number_of_people.isnumeric():
number_of_donuts = input("Enter number of donuts each person will want: ")
if number_of_donuts.isnumeric():
min_box = (number_of_people * number_of_donuts) // 12
box_remainder = (number_of_people * number_of_donuts) % 12
if box_remainder != 0:
min_box = min_box + 1
print("Minimum boxes of donuts needed: ", min_box)
donuts_left = (min_box * 12) - (number_of_people * number_of_donuts)
print("Donuts left over:", donuts_left)
if min_box <= 5:
donut_cost = 8 * min_box
elif min_box <= 20:
donut_cost = 7.50 * min_box
else:
donut_cost = 6 * min_box
print ("Donuts cost: ",format(donut_cost, '.2f'))
else:
print(number_of_donuts, "is not a valid number")
else:
print (number_of_people, "is not a valid number")
我真的很困惑。我希望能够告诉用户他们输入了错误的输入,但是如果我将输入更改为int(输入。我不知道如何通知用户,如果他们没有输入一个int值。不能乘以非Int Python的序列
错误我收到 类型错误:无法按类型“STR”
我想我能猜到,但以供将来参考,请包括它告诉我们错误(尤其是剩下的部分它在哪条线上)。 – smarx