這是一個問題,我的任務在編程的介紹和我不完全理解如何做到這一點,而不使用Ifs因爲我們的教授只是想要基本模數和分裂。我試圖得到3個輸出。氣球大於兒童(工作),氣球等於只輸出0和0的兒童,氣球比兒童小,這不起作用。Python 2.7計算餘數與除法和兩個輸入
# number of balloons
children = int(input("Enter number of balloons: "))
# number of children coming to the party
balloons = int(input("Enter the number of children coming to the party: "))
# number of balloons each child will receive
receive_balloons = int(balloons % children)
# number of balloons leftover for decorations
remaining = children % balloons
print("{:s}""{:d}""{:s}""{:d}".format("Number of balloons for each child is ", receive_balloons, " and the amount leftover is ", remaining))
print(balloons, "", (remaining))
你覺得呢''%呢?你的這兩個用法都不正確。 – user2357112
它是不是將它分開並計算餘數? – roysizzle
它的確如此,所以你的問題可能與數學有關。你爲什麼認爲將氣球數量除以兒童數量的餘數*是每個孩子接收到的氣球數量?你爲什麼要將*孩子的數量除以*氣球的數量*,並將其餘部分用於找出剩餘氣球的數量? – user2357112