WARNING: This program has a logic error. It doesn't cause an error message, but something isn't quite right.

modulo % calculates the remainder of division! This program splits up candy among a group of friends and calculates how much candy is leftover.

  • Click Run and enter a number between 1 and 10. Look at the stage. What's wrong with the output?
  • Fix the program by replacing the division operator / with the modulo operator %.

To navigate the page using the TAB key, first press ESC to exit the code editor.

amount_of_candy = 10 amount_of_people = int(stage.ask("How many people are sharing? Enter a number between 1 and 10!")) leftovers = amount_of_candy/amount_of_people if leftovers != 0: # sprite = codesters.Text("text", x, y) sprite = codesters.Text("There are " + str(leftovers) + " candies left over!", 0, 150)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)