0% found this document useful (0 votes)
2 views

Recursive programs

The document contains several simple Python programs demonstrating the use of boolean functions for various tasks, including checking if a number is greater than one, checking divisibility, and determining if a number is prime. It also includes programs for calculating factorials and generating Fibonacci series. Each program prompts the user for input and prints the result based on the defined functions.

Uploaded by

riaz ahamed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Recursive programs

The document contains several simple Python programs demonstrating the use of boolean functions for various tasks, including checking if a number is greater than one, checking divisibility, and determining if a number is prime. It also includes programs for calculating factorials and generating Fibonacci series. Each program prompts the user for input and prints the result based on the defined functions.

Uploaded by

riaz ahamed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Simple Python Program for boolean function

def a_function():
return True

output = a_function()
print(output)

2. Python Program for checking a number is bigger than one using boolean function

def is_bigger_than_one(number):
if number > 1:
return True
else:
return False

num=int(input("Enter a value:"))
print(is_bigger_than_one(num))

3. Python Program for checking a number is divisible by another using boolean function

def isDivisible(x, y):


if x % y == 0:
result = True
else:
result = False
return result

a=int(input("Enter the value for a:"))


b=int(input("Enter the value for b:"))
print(isDivisible(a, b))

4. Python Program for checking a number is prime or not using boolean function

def isprime(num):
if num> 1:
for n in range(2,num):
if (num % n) == 0:
return False
return True
else:
return False
num=int(input("Enter a number:"))
print(isprime(num))
5. Python Program to print the factorial of a number

def factorial(n):
if n == 1:
return n
else:
return n * factorial(n-1)

num=int(input("Enter the number for factorial:"))


if num < 0:
print("Invalid input ! Please enter a positive number.")
elif num == 0:
print("Factorial of number 0 is 1")
else:
print("Factorial of number", num, "=", factorial(num))

6. Python Program to print the fibonacci series upto n_terms

def recursive_fibonacci(n):
if n <= 1:
return n
else:
return(recursive_fibonacci(n-1) + recursive_fibonacci(n-2))

n_terms = int(input("Enter the number for fibonacci:"))


if n_terms <= 0:
print("Invalid input ! Please input a positive value")
else:
print("Fibonacci series:")
for i in range(n_terms):
print(recursive_fibonacci(i))

You might also like