To solve a problem in Pythonic way

Hi today I have tried to solve one of the problem given by friend in python. The question of him was . Once a grandma who sells eggs get accident and all the eggs on his bag was broken . And because of it  she have to give count of all the broken eggs to his owner. But she doesnt know how the total count of eggs , she only remembers that while keeping the eggs in 1 number the remainder egg would be 1 , Similarly for 2,3,4,5,6 all the remainder would be 1. And while keeping 7 at a time the remainder would be 0. Now how we can find the total number of eggs in a python program is just simple as this.

while 1:
for i in range(1, 1000):
if (i%2) == 1 and (i%3) == 1 and (i%4) == 1 and (i%5) == 1 and (i%6 == 1) and (i%7 == 0):
print i
break

No comments:

Post a Comment