What is Range and Recursive function in python?

Description

To see what is range() function and recursion
in python and its important uses.

Range().

   It generates sequence of
numbers in a given interval.

   It starts its index position
as zero, unless index position is
declared explicitly.

Eg.>>>range(5)

  Above code produce 0,1,2,3,4

  Its very useful for generating
loop sequence like pattern programs,
prime numbers ,etc..

Recursive function.

  Which function is called by itself
when the program is running,
that is called recursive function.

  Recursion works like a loop.

Source code(Floyd pattern):

#Get input from user

n = int(input

(“Enter the number of rows:”))

#make first loop sequence

for i in range(n+1):

#make second loop

for j in range(i):

#printing the pattern

print(“*”,end=””)

print()

Source code(Factorial program):

#recursive function

print(“Factorial using recursion******”)

def calc_factorial(x):

if(x==1):

return 1

else:

return(x*(calc_factorial(x-1)))

#get input from user

n=int(input(“Enter the number:”))

#method calling statements

print(“the factorial of given number is:”,

calc_factorial(n))

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit