Files

- main.py

main.py

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

```
# Solves #6 Rollover Numbers Problem from:
# http://www.playwithyourmath.com/
# This function takes a number (like 1234 in the example)
# "rolls it over" and returns the sum
# This function is called repeatedly in the look_for_rollovers function
def rollover_sum(first_number):
"""
Given a number, follows rollover process and finds sum
"""
addend1 = first_number
addend2 = int(str(first_number)[1:] + str(first_number)[0])
sum = addend1 + addend2
return sum
# This function checks every number from 1 to goal to see if rolling over
# results in the goal. It uses the above function
def look_for_rollovers(goal):
print ' '
print 'Checking if', goal, 'is a rollover number...'
did_it_find_one = 0
#This for loop tests every number from 1 to the goal to find solutions
for i in range (1, goal):
#Tests if the number it is trying makes the goal when rolled over
if rollover_sum(i) == goal:
print i, 'makes', goal, 'when rolled over'
did_it_find_one += 1
if did_it_find_one == 0:
print goal, 'is not a rollover number.'
else: print goal, 'is a rollover number.'
#this runs the test on the numbers given for the problem
look_for_rollovers(3575)
look_for_rollovers(8612)
look_for_rollovers(4322)
look_for_rollovers(9867)
look_for_rollovers(13859)
```