Prog.1: Write a program in python to find addition of two numbers.
#Addition of two numbers
num1=int(input('Enter the first number\t:'))
num2=int(input('Enter the second number\t:'))
print('\nThe numbers entered are ', num1, ' & ', num2)
c=num1+num2
print('\nThe numbers now are ', c)
Prog. 2:Write a program in python to swap two numbers.
#Swapping of Two numbers
num1=int(input('Enter the first number\t:'))
num2=int(input('Enter the second number\t:'))
print('\nThe numbers entered are ', num1, ' & ', num2)
(num1, num2) = (num2, num1)
print('\nThe numbers now are ', num1, ' & ', num2)
Program 3: Write a Program in Python to find roots of quadratic equation.
# import complex math module import cmath
a = float(input('Enter a: '))
b = float(input('Enter b: '))
c = float(input('Enter c: '))
# calculate the discriminant
d = (b**2) - (4*a*c)
# find two solutions
m = (-[Link](d))/(2*a)
n = (-b+[Link](d))/(2*a)
print('The roots of the quadratic equations are', m, ‘and’, n)
Explanation -
In the first line, we have imported the cmath module and we have defined three variables named
a, b, and c which takes input from the user. Then, we calculated the discriminant using the
formula. Using the [Link]() method, we have calculated two solutions and printed the
result.
Program 4: Write a Program in Python to find entered number is prime or not.
#number is prime or not
num=int(input("Enter any number: "))
if num==1:
print(‘ Entered number is not prime’)
if num>1:
for i in range(2, num):
if num%i == 0:
print("This number is not prime")
break
else:
print("This number is prime")
Program 5: write a program in python to find factorial of a number using
while loop.
#Factorial of number using while loop
m = int(input('Enter number whose factorial is required:'))
factorial = 1 #initialize
i=1 # loop counter variable
while i<=m:
factorial =factorial*i
i=i+1
print("factorial of ", m, " is ", factorial)