Reference no: EM132355284
Question
a) In a file named zap.py, write function called zap which accepts any positive integer parameter and returns the sum of the squares of its digits. For example, zap( 73 ) will return 58 because 72 + 32 = 58 zap( 4 ) will return 16 because 42 = 16
b) If we keep zapping the result of a previous zap, we generate a sequence of integers which will eventually produce either 1 or 4. For example, if we start with 73:
zap( 73 ) -> 58 or, if we start with 44:
zap( 58 ) -> 89 zap( 44 )-> 32
zap( 89 ) -> 145 zap( 32 ) -> 13
zap( 145 )-> 42 zap( 13 ) ->10
zap( 42 )-> 20 zap( 10 ) -> 1
zap( 20 ) -> 4
Numbers which zap to 1 are called 'Happy Numbers' and those which zap to 4 are called 'Unhappy Numbers'. In the same file as (a), write boolean function called happy which takes an integer and determines if it is happy or not.
c) i) write complete program named happyNumbers.py which allows user to enter a positive integer number, n, and display all the happy numbers from 1 up to n.
ii) Write complete program named lovers.py which display all the pairs of consecutive happy numbers between 1 and 1000. (Such pairs are called 'lovers'.)
Some of the pairs include (but are not limited to):
192, 193
301, 302
622, 623
637, 638
931, 932