Recursion Practice Set

#1 def writeNumbers(num): if num != 0: print(num) writeNumbers(num-1) #2 def factorial(num): if num ==1: return num else: return num*factorial(num-1) #3 def multiplyAll(n): if n ==1 : return n else: return 1/n * multiplyAll(n-1) #4 def triangle(num): if num ==1: return num-5 else: return num+triangle(num-1) #5 ##char = "" ##num = int(input("enter an int")) ##def printChar(num): ## global num1 ## global char ## if num % 2 ==0: ## num1 = num1 //2 ## num1 = num1 -1 ## for x in range(0,num1,1): ## char += "\\" ## char = char + "^^" ## for x in range(num,num-num1,-1): ## char = char + "/" ## else: ## num1 = num1 //2 ## for x in range(0,num1,1): ## char += "\\" ## char = char + "^" ## for x in range(num,num-num1,-1): ## char = char + "/" ## print(char) ##num1 = num ##printChar(num) #6 def count(num): if num == 0: return num elif str(num)[len(str(num))-1] =="2": return count(num//10)+1 else: print(num) return count(num//10) x = count(131427732) print(x)
1