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 파이썬으로 시퀀스를 곱할 수 없다
오류 내가받을 형식 오류 : 타입 'STR'
내가 그것을 추측 할 수 있었다 생각 (나는.
int
들에str
들 변환 할x = int(x)
라인을 추가),하지만 나중에 참조 할 수 있도록, 우리에게 오류 (특히 부분의 나머지 부분을 포함하십시오 어느 선이 있는지). – smarx