# This program is supposed to do a division calculation. # You give it the dividend and divisor, and it's supposed to calculate the quotient and the remainder. # Reminder of the definitions of these terms: In the calculation 32 / 5 = 6 R 2... # The dividend is 32 (the number being divided) # The divisor is 5 (the number that you're dividing by) # The quotient is 6 (the times the divisor goes into the dividend completely) # The remainder is 2 (the pieces leftover after making groupings) # Your task is to fix the code so that the calculation works correctly. If you have more programming experience, # you might want to completely rewrite the code. Otherwise, you can follow along with the logic of the program # and find the error # # IDEA OF CODE: # Define the dividend and the divisor # The goal will be to do division by counting up groups. # For the 32 / 5 example, it should go... # # 1 group(s) = 5 pieces # 2 group(s) = 10 pieces # 3 group(s) = 15 pieces # 4 group(s) = 20 pieces # 5 group(s) = 25 pieces # 6 group(s) = 30 pieces # 7 group(s) = 35 pieces --- TOO MANY # 30 out of 32 pieces leaves 2 leftover # 32 / 5 = 6 R 2 Dividend = 32 Divisor = 5 Groupings = 0 TotalPieces = 0 while TotalPieces < Dividend: TotalPieces = TotalPieces + Dividend Groupings = Groupings + 1 if TotalPieces < Dividend: print "{} group(s) = {} pieces".format(Groupings, Dividend) else: print "{} group(s) = {} pieces --- TOO MANY".format(Groupings, TotalPieces) Remainder = TotalPieces - Dividend print "{} out of {} pieces leaves {} leftover".format(Dividend, TotalPieces, Remainder) print "{} / {} = {} R {}".format(Divisor, Dividend, Groupings, Remainder)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question