Reputation: 594
I need to solve this problem I have a parameter call num, this parameter is a number consist of number that has one column or more like 1 or 222 or 33 so on. for instance, if I typed 39 the number will multiplication as following 3 * 9 to equal to 27 which consists of two columns are 2 and 7 therefore I'll multiplication 2 * 7 to be 14 the end of this process the number will be consist of one column is 4. when a number will be equal to one column I will edit the num to be 0 I need just to loop this process many and many times until the remaining one column to be equal to zero how can I do so?
this is my function
def presistance(num):
mult = 1
arr = []
i = 0
# check if num > 9
while True:
# numbers in array
if num > 9:
for n in str(num):
arr.append(int(n))
for n in arr:
mult *= n
return mult
else:
num = 0
return num
print(presistance(39))
Upvotes: 0
Views: 652
Reputation: 91
Instead of returning mult you can simply set num equal to mult. Then the code will loop again in the while loop and check the next case and keep going until num only has one digit.
while True:
# numbers in array
mult = 1
arr = []
if num > 9:
for n in str(num):
arr.append(int(n))
for n in arr:
mult *= n
num = mult
print(num)
else:
num = 0
return num
Upvotes: 1