Recursion in Python
Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python
Program 1
# Recursion Application # a=1 # sum=0 # def display(n): # Recursive # global a,sum # if(a>n): # return # print(a,end=" ") # sum+=a # #print(a*a) # a=a+1 # display(n) # #calling # n=int(input("Enter the limit")) # display(n) # print("\nTotal is :",sum) # Factorial of number using recursion # f=1 # def factorial(n): # global f # if(n==0): # return(f) # f=f*n # n=n-1 # factorial(n) # #Calling # n=int(input("Enter a number")) # x=factorial(n) # print("factorial is : ",f) # Reverse of Number using recursion #calling # n=int(input("Enter a number")) # reverseno(n) # print("Reverse is : ",s) # if(n==s): # print("No is palindrom") # else: # print("No is not palindrom") # Addition of Digit # s=0 # def additiondigit(n): # global s # if(n==0): # return # r=n%10 # s=s+r # n=n//10 # additiondigit(n) # #calling # n=int(input("Enter a number")) # additiondigit(n) # print("Result is : ",s) # Armstrong of Number using recursion s=0 def armstrong(n): global s if(n==0): return r=n%10 s=s+(r*r*r) n=n//10 armstrong(n) n=int(input("Enter a number")) armstrong(n) if(n==s): print("No is armstrong") else: print("No is not armstrong") #Calling
Your opinion matters
Please write your valuable feedback about DataFlair on Google