-1

A jar of Halloween candy contains an unknown amount of candy and if you can guess exactly how much candy is in the bowl, then you win all the candy. You ask the person in charge the following: If the candy is divided evenly among 5 people, how many pieces would be left over? The answer is 2 pieces. You then ask about dividing the candy evenly among 6 people, and the amount left over is 3 pieces. Finally, you ask about dividing the candy evenly among 7 people, and the amount left over is 2 pieces. By looking at the bowl, you can tell that there are less than 200 pieces. Write a program to determine how many pieces are in the bowl.

Isacc Barker
  • 507
  • 4
  • 15
Bonn
  • 21
  • 1
  • 4
  • This problem is based on Brian Heinold Intro to Python and can't find solutions for it. Please help me. – Bonn Mar 25 '20 at 14:26
  • 2
    Stack Overflow is not a free coding service, you are expected to show your efforts and specific problems. You should read [how to ask](https://stackoverflow.com/help/how-to-ask) – dspencer Mar 25 '20 at 14:26
  • Good place to start researching is the modulo operator `%`, beyond that: "can't find solutions for it" -> Break it don into components, research each necessary component, and write your own solution – G. Anderson Mar 25 '20 at 14:32

2 Answers2

0

This isn't the kind of question that is asked on Stack Overflow. However, I think you deserve an answer. You seem like a beginner (: so I would loop through all the numbers from 0 to 200 and check the conditions. Just so you know, the % operator returns the remainder of two numbers. Here is some sample code:

for candies in range(200):
    if (candies % 5 != 2):
        continue
    if (candies % 6 != 3):
        continue
    if (candies % 7 != 2):
        continue

    print(str(candies) + " is the answer!")
    break
bashBedlam
  • 1,402
  • 1
  • 7
  • 11
Isacc Barker
  • 507
  • 4
  • 15
0

Code

x=200

for i in range(x):

    if i % 5 == 2:
       if i % 6 == 3:
          if i % 7 == 2:
             print(i, 'candies are in the bowl!')