Es ist eine Frage für meine Aufgabe im Intro Programmierung, und ich verstehe nicht ganz, wie dies ohne den Einsatz von Ifs zu tun, weil unser Prof nur Grundmodul und Division will. Ich versuche, 3 Ausgänge zu bekommen. Ballons größer als Kinder (was funktioniert), Ballons gleich Kinder, die nur 0 und 0 ausgibt und Ballons weniger als Kinder, was nicht funktioniert.Python 2.7 Berechnung Rest mit Division und zwei Eingaben
# 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))
Was verwenden denken Sie, '%' tut? Keine Ihrer Anwendungen davon ist richtig. – user2357112
Teilt es es nicht und berechnet den Rest? – roysizzle
Es tut, also ist Ihr Problem wahrscheinlich mit der Mathematik. Warum denkst du, dass der * Rest * beim Teilen der Anzahl der Ballons durch die Anzahl der Kinder die Anzahl der Ballons ist, die jedes Kind erhält? Warum teilst du die Anzahl der * Kinder * durch die Anzahl der * Ballons * auf und nimmst den Rest, um die Anzahl der übriggebliebenen Ballons zu finden? – user2357112