1. Python program to check whether the given number is even or not
a=int(input("Enter a number"))
if a%2==0:
print(f"{a} number is even")
else:
print(f"{a} number is add")
2. Python program to convert the temperature in degree centigrade to Fahrenheit
a=int(input("Enter c or f\n1.temperature in degree centigrade \n2.temperature in degree Fahrenheit\n enter no: "))
if a==1:
b=float(input("provide temperature input in Celsius:"))
d= (b* 9/5) + 32
print('%0.2f degree celsius is equal to %0.2f degree fahrenheit' %(b,d))
elif a==2:
b=float(input("provide temperature input in Fahrenheit:"))
d= (b-32) / 1.8
print('%0.1f degrees Fahrenheit is equivalent to %0.1f degrees Celsius' %(b,d))
else:
print("wrong input")
3. Python program to find the area of a triangle whose sides are give
print("Enter the sides->")
a=int(input("\nEnter first side::"))
b=int(input("\nEnter second side::"))
c=int(input("\nEnter third side::"))
#calculate semi parameter
s=(a+b+c)/2
area=(s*(s-a)*(s-b)*(s-c))**0.5
print('the area of triangle is %0.2f'%area)
4. Python program to find out the average of a set of integers
size=int(input("Enter the number of elements you want to average : "))
arr=[]
#taking input of the list
for i in range(0,size):
elem=int(input("Please give value for index "+str(i)+": "))
arr.append(elem)
#taking average of the elements of the list
avg=sum(arr)/size
print("Average of the array elements is ",avg)
5. Python program to find the product of a set of real numbers
product = 1
count = int(input("Enter the number of real numbers: "))
for i in range(0,count):
x = float(input("Enter a real number: "))
product = product * x
print("The product of the numbers is: ", product)
6. Python program to find the circumference and area of a circle with a given radius
r = float(input("Input the radius of the circle: "))
c = 2 * 3.14 * r
area = 3.14 * r * r
print("The circumference of the circle is: ", c)
print("The area of the circle is: ", area)
7. Python program to check whether the given integer is a multiple of 5
number = int(input("Enter an integer: "))
if(number%5==0):
print(number, "is a multile of 5")
else:
print(number, "is not a multiple of 5")
8. Python program to check whether the given integer is a multiple of both 5 and 7
number = int(input("Enter an integer: "))
if((number%5==0)and(number%7==0)):
print(number, "is a multiple of both 5 and 7")
else:
print(number, "is not a multiple of both 5 and 7")
9. Python program to find the average of 10 numbers using while loop
count = 0
sum = 0.0
while(count<10):
number = float(input("Enter a real number: "))
count=count+1
sum = sum+number
avg = sum/10;
print("Average is :",avg)
10. Python program to display the given integer in reverse manner
number = int(input("Enter a positive integer: "))
rev = 0
while(number!=0):
digit = number%10
rev = (rev*10)+digit
number = number//10
print(rev)
11. Python program to find the sum of the digits of an integer using while loop
sum = 0
number = int(input("Enter an integer: "))
while(number!=0):
digit = number%10
sum = sum+digit
number = number//10
print("Sum of digits is: ", sum)
12. Python program to display all the multiples of 3 within the range 10 to 50
for i in range(10,50):
if (i%3==0):
print(i)
13.Python program to display all integers within the range 100 -200 whose sum of digits is an even number
for i in range(100,200):
num = i
sum = 0
while(num!=0):
digit = num%10
sum = sum + digit
num = num//10
if(sum%2==0):
print(i)
14. Python program to check whether the given integer is a prime number or no
num = int(input("Enter an integer greater than 1: "))
isprime = 1 #assuming that num is prime
for i in range(2,num//2):
if (num%i==0):
isprime = 0
break
if(isprime==1):
print(num, "is a prime number")
else:
print(num, "is not a prime number")
15. Python program to generate the prime numbers from 1 to N
num =int(input("Enter the range: "))
for n in range(2,num):
for i in range(2,n):
if(n%i==0):
break
else:
print(n)
16. Python program to find the roots of a quadratic equatio
import math
a = float(input("Enter the first coefficient: "))
b = float(input("Enter the second coefficient: "))
c = float(input("Enter the third coefficient: "))
if (a!=0.0):
d = (b*b)-(4*a*c)
if (d==0.0):
print("The roots are real and equal.")
r = -b/(2*a)
print("The roots are ", r,"and", r)
elif(d>0.0):
print("The roots are real and distinct.")
r1 = (-b+(math.sqrt(d)))/(2*a)
r2 = (-b-(math.sqrt(d)))/(2*a)
print("The root1 is: ", r1)
print("The root2 is: ", r2)
else:
print("The roots are imaginary.")
rp = -b/(2*a)
ip = math.sqrt(-d)/(2*a)
print("The root1 is: ", rp, "+ i",ip)
print("The root2 is: ", rp, "- i",ip)
else:
print("Not a quadratic equation.")