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 root of a number Calculator")
print("-"*50)num = input("Enter a number: ")def droot(num):if len(num) == 1:return numelse:sum = 0for i in num:sum += int(i)num = str(sum)return droot(num)print("The digital root of ", num, " is: ", droot(num))
Basically, you're looking for something like this:
number = 9876; #Example
divider = 1;
digits = []
answer = -1
while true:value = 1while number % divider != 0: #Fills list with digitsdigits.append(number % divider)divider = divider * 10while list.len() != 0: # Empty list for next iterationvalue = value * list[0]list.remove(0) # The elements will always be 0, as the first one is constantly removednumber = value # Change for next iterationif value == value % 10: # If there's only a single digit left, you've got itanswer = value # Finish up, closebreak