You are on page 1of 10

Name – Shivang Badoni Section - G1

Course – BCA(4 )
th
Roll no – 68
Problem Statement 16: Python Program to add two numbers using function.

Code:

def sum(x,y):
return x+y
a,b = int(input("Enter first number:")),int(input("Enter second number:"))
print("Sum of two number is",sum(a,b))

Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )
th
Roll no – 68
Problem Statement 17: Python Program to swap two numbers using function.

Code:

def Swap(x,y):
x,y=y,x
print("First number is :",x)
print("Second number is :",y)
a,b = int(input("Enter first number:")),int(input("Enter second number:"))
print("Before swap")
print("First number is :",a)
print("Second number is :",b)
print("After swap")
Swap(a,b)
Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )
th
Roll no – 68
Problem Statement 18: Python Program to Find Factorial of Number using
function.

Code:

def Factorial(x):
fact=1
while (x>0):
fact=fact*x
x=x-1
return fact
a = int(input("Enter num:"))
print("factorial of num is",Factorial(a))
Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )
th
Roll no – 68
Problem Statement 19: Python Program to check number is prime or not using
function.

Code:

def Prime(x):
for i in range(2,x//2):

if x%i==0:
print(f"{x} is not prime num.")
break
else:
print(f"{x} is prime num.")
num=int(input("Enter number :"))
print(Prime(num))

Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )th
Roll no – 68
Problem Statement 20: Python Program to calculate sum of digits of a number
using function.

Code:

def sum_of_digits(num):
sum_digits = 0
while num > 0:
digit = num % 10
sum_digits += digit
num //= 10
return sum_digits

num = int(input("Enter a number: "))


result = sum_of_digits(num)
print("Sum of digits:", result)

Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )
th
Roll no – 68
Problem Statement 21: Python Program to Find Factorial of Number Using
Recursion.

Code:

def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
n=int(input("Enter a Number :"))
print(f"factorial of {n} is ",factorial(n))
Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )
th
Roll no – 68
Problem Statement 22: Python Program to Find the Sum of 10 Natural
Numbers.

Code:

def sum_of_natural_numbers(n):
return (n * (n + 1)) // 2

number = int(input("Enter a number: "))


result = sum_of_natural_numbers(number)
print("Sum of natural numbers is", result)
Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )
th
Roll no – 68
Problem Statement 23: Python Program to Find LCM using function.

Code:

def LCM(num1,num2):
max_num = max(num1, num2)
result = max_num
while result%num1 != 0 or result%num2 != 0:
result += max_num
return result

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))
print("LCM of", num1, "and", num2, "is:", LCM(num1,num2))
Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )
th
Roll no – 68
Problem Statement 24: Python Program to Display the Table of a number.

Code:

def table(x):
for i in range (1,11):
mul=x*i
print(f"{x} * {i} = {mul} ")

x=int(input("enter a number :"))


table(x)

Output:
Name – Shivang Badoni Section - G1
Course – BCA(4 )
th
Roll no – 68
Problem Statement 25: Python Program to Display the even numbers between
1 to 100.

Code:

def even_no():
for num in range(1, 101):
if num % 2 == 0:
print(num)
even_no()
Output:

You might also like