Multiplicative Digital Root Of A Number Using Loops
I need to find the multiplicative digital root of a number in python using only loops. something that does the same as the below code but using loops: print('multiplicative digital
Solution 1:
Basically, you're looking for something like this:
number = 9876; #Example
divider = 1;
digits = []
answer = -1
while true:
value = 1
while number % divider != 0: #Fills list with digits
digits.append(number % divider)
divider = divider * 10
while list.len() != 0: # Empty list for next iteration
value = value * list[0]
list.remove(0) # The elements will always be 0, as the first one is constantly removed
number = value # Change for next iteration
if value == value % 10: # If there's only a single digit left, you've got it
answer = value # Finish up, close
break
Solution 2:
def d_root(num):
temp=num
c=0
while 1:
p=1
c=c+1
while temp!=0:
rem=temp%10
p=p*rem
temp=int(temp/10)
if p<10:
print("Multiplicative Presistance ",c)
print("Multiplicative Digital Root ",p)
break
temp=p
n=int(input("Enter any Number "))
d_root(n)
Solution 3:
def digital_root(num):
temp=num
while(1):
p=1
while temp!=0:
rem=temp%10
p=p*rem
temp=int(temp/10)
if p<10:
print(p)
break
temp=p
num=int(input("Enter number"))
digital_root(num)
Post a Comment for "Multiplicative Digital Root Of A Number Using Loops"