Python Persistent number -
this question has answer here:
- computing persistence number of integer 3 answers
need assistance write persistent number program in python determine smallest non-negative integer persistence (715 ---> 35 ---> 15 ---> 5) of 3, 4, 5, 6, 7. output following format:
the smallest integer persistence of 3 is: 39 smallest integer persistence of 4 is: xx smallest integer persistence of 5 is: xxx smallest integer persistence of 6 is: xxxx smallest integer persistence of 7 is: xxxxx
any code links or leads appreciated, thanks.
def main(): low_limit = 3 high_limit = 7 limit in range(low_limit, high_limit+1): number = 1 while persistence(number) < limit: number += 1 print('the smallest integer persistence of', limit, 'is:', number) def persistence(x): pcount = 0 # counting p 0 while x>=10: y=x # temp copy of x z=1 # z holds value of y being broken down , multplied while (y!=0): z=z*(y%10) # stripping last number , mult last z value y=y//10 # integer division, dropping off last digit x=z pcount +=1 return pcount main()
Comments
Post a Comment