Program - 1 - Write a program to input a welcome message and print it.
1 message=input("Enter welcome message :")
2 print("Hello,",message)
Enter welcome message :Python welcomes you .
Hello, Python welcomes you .
Program - 2 - Program to obtain three numbers and print their sum.
1 num_1 = int(input("Enter number 1 :"))
2 num_2 = int(input("Enter number 2 :"))
3 num_3 = int(input("Enter number 3 :"))
4 sum =num_1 + num_2 + num_3
5 print("The three numbers are :",num_1,",",num_2,",",num_3)
6 print("Sum is : ",sum)
Enter number 1 :5
Enter number 2 :25
Enter number 3 :85
The three numbers are : 5 , 25 , 85
Sum is : 115
Program - 3- Program to obtain length and breadth of a rectangle and calculate its area.
1 length = float(input("Entre length of the rectangle :"))
2 breadth = float(input("Enter breadth of the rectangle :"))
3 area = length * breadth
4 print("Rectangle Specifications :")
5 print("Length :",length)
6 print("Breadth :",breadth)
7 print("Area : ",area)
Entre length of the rectangle :33
Enter breadth of the rectangle :17.5
Rectangle Specifications :
Length : 33.0
Breadth : 17.5
Area : 577.5
Program - 4- Program to calculate B.M.I(Body Mass Index) of a person.
1 weight_in_kg = float(input("Enter weight in kg :"))
2 height_in_meter = float(input("Enter height in meters :"))
3 bmi = weight_in_kg/(height_in_meter * height_in_meter)
4 print("BMI is : ",bmi)
Enter weight in kg :66
Enter height in meters :1.6
BMI is : 25.781249999999996
Program - 5-Write a program to input a number and print its cube.
1 num = int(input("Enter a number : "))
2 cube = num * num * num
3 print("Number is : ",num)
4 print("Its cube is :",cube)
Enter a number : 12
Number is : 12
Its cube is : 1728
Program - 6 - Write a program to input a value in kilometres and convert it into miles(1 km =
0.621371 miles).
1 km = int(input("Enter kilometres : "))
2 miles = km * 0.621371
3 print("Kilometres :",km)
4 print("Miles :",miles)
Enter kilometres : 25
Kilometres : 25
Miles : 15.534275000000001
Program - 7 - Write a program to input a value in tones and convert into quintals and kilograms. (1
tonne = 10 quintals , 1 tonnes = 1000 kgs , 1 quintals = 100 kgs)
1 tonnes = float(input("Enter tonnes : "))
2 quintals = tonnes * 10
3 kgs = quintals * 100
4 print("Tonnes :",tonnes)
5 print("Quintals : ",quintals)
6 print("Kilograms : ",kgs)
Enter tonnes : 2.5
Tonnes : 2.5
Quintals : 25.0
Kilograms : 2500.0
Program - 8 - Write a program to input two numbers and swap them .
1 n_1 = int(input("Enter number 1 :"))
2 2 i t(i t(" t b 2 "))
2 n_2 = int(input("Enter number 2 :"))
3 print("Original numbers : ",n_1,",",n_2)
4 n_1 , n_2 = n_2 , n_1
5 print("After swapping :",n_1 ,",",n_2)
Enter number 1 :2
Enter number 2 :3
Original numbers : 2 , 3
After swapping : 3 , 2
Program - 9 - Write a program to input three numbers and swap them as the : 1st number become
the 2nd number , 2nd number becomes the 3rd number and the 3rd number become the 1st number
.
1 x = int(input("Enter number 1 :"))
2 y = int(input("Enter number 2 :"))
3 z = int(input("Enter number 3 :"))
4 print("Original numbers : ",x,",",y,",",z)
5 x , y , z = y , z , x
6 print("After swapping :",x,",",y,",",z)
Enter number 1 :5
Enter number 2 :7
Enter number 3 :2
Original numbers : 5 , 7 , 2
After swapping : 7 , 2 , 5
Program - 10 - A triangle has three sides a , b ,c as 17 , 23 , 30. Calculate and display its area using
Heron's formula as:
1 import math
2 a , b , c = 17 , 23 , 30
3 s = (a + b + c)/2
4 area = math.sqrt( s * (s - a) * ( s - a) * ( s - c) )
5 print("Sides of triangle :", a , b , c )
6 print("Area :", area , "units square")
Sides of triangle : 17 23 30
Area : 238.11761799581316 units square
Program - 11 - Write a program to calculate the perimeter of a triangle .
1 side_1 = float(input("Enter side 1 :"))
2 side_2 = float(input("Enter side 2 :"))
3 side_3 = float(input("Enter side 3 :"))
4 perm = side_1 + side_2 + side_3
5 print("The perimeter of given triangle is ",perm)
Enter side 1 :12
Enter side 2 :34
Enter side 3 :32
The perimeter of given triangle is 78.0
Program - 12 - Write a program to nd sale price of a item with given price and discount(%) .
1 price = float(input("Enter price :"))
2 dp = float(input("Enter discount % :"))
3 discount = price * dp / 100
4 sp = price - discount
5 print("Cost Price = ",price)
6 print("Discount = ",discount)
7 print("Selling Price =",sp)
Enter price :5000
Enter discount % :20
Cost Price = 5000.0
Discount = 1000.0
Selling Price = 4000.0
Program - 13 - Write a program to claculate Coumpound interest .
1 import math
2 prin = float(input("Principal Amount :"))
3 rate = float(input("Rate of Interest :"))
4 time = float(input("Time(in years) :"))
5 # si = (prin * rate * time)/100
6 amt = prin *(math.pow((1 + rate / 100),time))
7 ci = amt - prin
8 print("Compound interest is ",ci)
9 # print(" Simple Interest :",si)
Principal Amount :5000
Rate of Interest :7.9
Time(in years) :5
Compound interest is 2312.6910873069937
Program - 14 - Program that takes a number and checks whether the given number is odd or even .
1 i t(i t("E t i t "))
1 num = int(input("Enter an integer :"))
2 if num %2 == 0:
3 print(num,"is EVEN number .")
4 else :
5 print(num,"is ODD number .")
Enter an integer :22
22 is EVEN number .
Program - 15 - Program to nd the minimum element from a list of elements along with its index in
the list .
1 lst = eval(input("Enter list :"))
2 length = len(lst)
3 min_ele = lst[0]
4 min_index = 0
5 for i in range(1,length) :
6 if lst[i] < min_ele :
7 min_ele = lst[i]
8 min_index = i
9 print("Given list is :",lst)
10 print("The minimum element of the given list is :")
11 print(min_ele,"at index",min_index)
Enter list :[12,23,45]
Given list is : [12, 23, 45]
The minimum element of the given list is :
12 at index 0
Program - 16 - Program to count the frequency of a given element in a list of numbers .
1 lst = eval(input("Enter list :"))
2 length = len(lst)
3 element = int(input("Enter element :"))
4 count = 0
5 for i in range(0,length) :
6 if element == lst[i] :
7 count += 1
8 if count == 0 :
9 print(element,"not found in given list")
10 else :
11 print(element,"has ferquency as ", count ,"in given list")
Enter list :[1,1,1,2,2,3,4,2,2,5,5,2,2,5]
Enter element :2
2 has ferquency as 6 in given list
Program - 17 - Write a program to check if the maximum element of the list lies in the rst half of
the list or in second half .
1 lst = eval(input("Enter a list :"))
2 ln = len(lst)
3 mx = max(lst)
4 ind = lst.index(mx)
5 if ind <= (ln/2) :
6 print("The maximum element",mx,"lies in the 1st half .")
7 else :
8 print("The maximum element",mx,"lies in the 2nd half .")
Enter a list :[6,8,11,6,12,7,16]
The maximum element 16 lies in the 2nd half .
Program - 18 - Write a program to input a list lst and two numbers M and N . Then create a list from
those lst elements which are divisible by both M and N .
1 lst = eval(input("Enter a list :"))
2 lst_2 = []
3 M , N = eval(input("Enter two numbers as M , N :"))
4 for num in lst :
5 if (num % M == 0 and num % N == 0) :
6 lst_2.append(num)
7 print("New created list is :",lst_2)
Enter a list :[6,8,11,6,12,7,16]
Enter two numbers as M , N :6,2
New created list is : [6, 6, 12]
Program - 19 - Write a program to input a list of numbers and ask for new element and its position .
Then insert the element at gievn position .
1 lst = eval(input("Enter list of integer :"))
2 print("Original list :",lst)
3 el = int(input("Enter new element :"))
4 ln = len(lst)
5 pos = int(input("Insert at position ? < " + str(ln) + ":"))
6 lst.insert(pos,el)
7 print("List after insertion :",lst)
Enter list of integer :[4,6,2,8]
Original list : [4, 6, 2, 8]
Enter new element :5
Insert at position ? < 4:3
List after insertion : [4, 6, 2, 5, 8]
Program - 20 - Write a program to create a dictionary to store names of states and their capitals .
1 stCap = {}
2 n = int(input("How many capitals you want to store ?"))
3 for i in range(n) :
4 st = input("Enter state :")
5 cap = input("Enter capital :")
6 stCap[st] = cap
7 print("States and their capitals are :")
8 print(stCap)
How many capitals you want to store ?5
Enter state :Maharashtra
Enter capital :Mumbai
Enter state :Bihar
Enter capital :Patna
Enter state :Assam
Enter capital :Dispur
Enter state :Karnatka
Enter capital :Bengluru
Enter state :Manipur
Enter capital :Imphal
States and their capitals are :
{'Maharashtra': 'Mumbai', 'Bihar': 'Patna', 'Assam': 'Dispur', 'Karnatka': 'Bengluru',
Could not connect to the reCAPTCHA service. Please check your internet connection and reload to get a reCAPTCHA
challenge.