プログラミングのイントロでの私の割り当てには問題があります。私たちの教授は基本的なモジュラスと除算がほしいから、Ifを使用しないとこれを行う方法をあまり理解できません。私は3つの出力を取得しようとしています。 (動作する)子供よりも大きい風船、0と0を出力する子供に等しい風船、子供の風船よりも小さい風船、それは働きません。Python 2.7除算と2つの入力で剰余を計算する
あなたの変数の割り当てを修正する必要が# 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