You are on page 1of 13

Program 1. To find average and grade for given marks.

sub1=int(input("Enter marks of the first subject: "))

sub2=int(input("Enter marks of the second subject: "))

sub3=int(input("Enter marks of the third subject: "))

sub4=int(input("Enter marks of the fourth subject: "))

sub5=int(input("Enter marks of the fifth subject: "))

avg=(sub1+sub2+sub3+sub4+sub5)/5

#printing average

print ("The average marks",avg)

if(avg>=90):

print("Grade: A")

elif(avg>=80 and avg<90):

print("Grade: B")

elif(avg>=70 and avg<80):

print("Grade: C")

elif(avg>=60 and avg<70):

print("Grade: D")

else:

print("Grade: F")

Output:

Enter marks of the first subject: 45

Enter marks of the second subject: 78

Enter marks of the third subject: 87

Enter marks of the fourth subject: 95

Enter marks of the fifth subject: 99

The average marks 80.8

Grade: B

>>>

Program 2. To find the sale price of an item with a given cost and discount (%).

cost_price=float(input("Enter Price : "))


discount_In_Percentage=float(input("Enter discount % : "))

discount=cost_price*discount_In_Percentage/100

saleing_price=cost_price-discount

print("Cost Price : ",cost_price)

print("Discount: ",discount)

print("Selling Price : ",saleing_price)

Output:

Enter Price : 560

Enter discount % : 10

Cost Price : 560.0

Discount: 56.0

Selling Price : 504.0

>>>

Program 3. To calculate perimeter/circumference and area of shapes such as triangle, rectangle,


square and circle.

#We will make use of user defined python functions for this task.

#we will import math library to use sqrt(), this will used to #calculate square root.

import math

def area_square(a):

area1=float(a*a);

print("Area of square is:",area1)

def area_circle(r):

area2=float(3.14*r*r);

print("Area of circle is:",area2)

def area_rectangle(a,b):

area3=float(a*b);

print("Area of rectangle is:",area3)

def area_triangle(x,y):

area4=float((x*y)/2);

print("Area of triangle is:",area4)


def peri_square(a):

peri1=float(4*a);

print("Perimeter of square is:",peri1)

def peri_circle(r):

peri2=float(2*3.14*r);

print("Perimter of circle is:",peri2)

def peri_triangle(a,b):

hypotenuse=float(math.sqrt(a*a+b*b))

peri3=float(a+b+hypotenuse)

print("Perimter of right angled triangle is:",peri3)

def peri_rectangle(a,b):

peri4=float(2*(a+b))

print("Perimter of rectangle is:",peri4)

side=float(input("enter the side of square:"))

area_square(side)

print()

peri_square(side)

radius=float(input("enter the radius of circle:"))

area_circle(radius)

peri_circle(radius)

length=float(input("enter the length of rectangle:"))

breadth=float(input("enter the breadth of rectangle:"))

area_rectangle(length,breadth)

peri_rectangle(length,breadth)

base=float(input("enter the base of right angled triangle:"))

height=float(input("enter the height of right angled triangle:"))

area_triangle(base,height)

peri_triangle(base,height)

Output:

enter the side of square:4


Area of square is: 16.0

Perimeter of square is: 16.0

enter the radius of circle:3

Area of circle is: 28.259999999999998

Perimter of circle is: 18.84

enter the length of rectangle:5

enter the breadth of rectangle:3

Area of rectangle is: 15.0

Perimter of rectangle is: 16.0

enter the base of right angled triangle:4

enter the height of right angled triangle:3

Area of triangle is: 6.0

Perimter of right angled triangle is: 12.0

>>>

Program 4.To calculate Simple and Compound interest.

# Simple and Compound Interest

# Reading principal amount, rate and time

principal = float(input('Enter amount: '))

time = float(input('Enter time: '))

rate = float(input('Enter rate: '))

# Calcualtion

simple_interest = (principal*time*rate)/100

compound_interest = principal * ( (1+rate/100)**time - 1)

# Displaying result

print('Simple interest is: %f' % (simple_interest))

print('Compound interest is: %f' %(compound_interest))

Output:

Enter amount: 500

Enter time: 5
Enter rate: 12

Simple interest is: 300.000000

Compound interest is: 381.170842

>>>

Program 5.To calculate profit-loss for a given Cost and Sell Price.

cp=float(input("Enter the Cost Price : "));

sp=float(input("Enter the Selling Price : "));

if cp==sp:

print("No Profit No Loss")

else:

if sp>cp:

print("Profit of ",sp-cp)

else:

print("Loss of ",cp-sp)

Output:

Enter the Cost Price : 575

Enter the Selling Price : 623

Profit of 48.0

>>>

Enter the Cost Price : 545

Enter the Selling Price : 545

No Profit No Loss

>>>

Enter the Cost Price : 545

Enter the Selling Price : 523


Loss of 22.0

>>>

Program 6. To calculate EMI for Amount, Period and Interest.

# Python program to calculate monthly EMI (Equated Monthly Installment)

# EMI Formula = p * r * (1+r)^n/((1+r)^n-1)

# If the interest rate per annum is R% then

# interest rate per month is calculated using:

# Monthly Interest Rate (r) = R/(12*100)

# Varaible name details:

# p = Principal or Loan Amount

# r = Interest Rate Per Month

# n = Number of monthly installments

# Reading inputs from user

p = float(input("Enter principal amount: "))

R = float(input("Enter annual interest rate: "))

n = int(input("Enter number of months: " ))

# Calculating interest rate per month

r = R/(12*100)

# Calculating Equated Monthly Installment (EMI)

emi = p * r * ((1+r)**n)/((1+r)**n - 1)

print("Monthly EMI = ", emi)

Output:

Enter principal amount: 12000

Enter annual interest rate: 12.5

Enter number of months: 18

Monthly EMI = 734.57478867545

>>>

Program 7.To calculate tax – GST / Income Tax.


Original_price=float(input("Enter original Price:-"))

Net_price = float(input("Enter Net Price:-"))

GST_amount = Net_price - Original_price

GST_percent = ((GST_amount * 100) / Original_price)

print("GST = ",end='')

print(GST_percent,end='')

print("%")

Output:

Enter original Price:-345

Enter Net Price:-356

GST = 3.1884057971014492%

>>>

Program 8.To find the largest and smallest numbers in a list.

Program 9.To find the third largest/smallest number in a list.

#create empty list

mylist = []

number = int(input('How many elements to put in List: '))

for n in range(number):

element = int(input('Enter element '))

mylist.append(element)

# Sort list elements

sorted_list = sorted(mylist)

print("Sorted elements in list : ",sorted_list)

'''Now we will print values using their index

(as third smallest element will be at index 2

and the third largest elemt wiill be at index -3)

'''

print(("The Third smallest element in list is:",sorted_list[2]))


print(("The Third largestest element in list is:",sorted_list[-3]))

Output:

How many elements to put in List: 6

Enter element 34

Enter element 45

Enter element 23

Enter element 32

Enter element 65

Enter element 56

Sorted elements in list : [23, 32, 34, 45, 56, 65]

('The Third smallest element in list is:', 34)

('The Third largestest element in list is:', 45)

>>>

Program 10.1 To find the sum of squares of the first 100 natural numbers.

'''Python Program to find the sum of

squares of the first 100 natural numbers'''

sum = 0

for numbers in range(1, 101):

sum = sum + (numbers*numbers)

print("Sum of squares is : ", sum)

Output:

Sum of squares is : 338350

>>>

Program 10.2 Python Program to find the sum of square of given number.
number = int(input("Enter any number : "))

sum = 0

for numbers in range(1,number+1):

sum = sum + (numbers*numbers)

print("Sum of squares is : ", sum)

Output:

Enter any number : 4

Sum of squares is : 30

>>>

Enter any number : 3

Sum of squares is : 14

>>>

Program 11.To print the first ‘n’ multiples of a given number.

# Python Program to print the first ‘n’ multiples of a given number

num=int(input("Enter a number whose multiples to find-"))

length=int(input("Enter length upto which you want to find multiples-"))

for i in range (1,length+1):

print(i*num)

Output:

Enter a number whose multiples to find-5

Enter length upto which you want to find multiples-4

10

15
20

>>>

Enter a number whose multiples to find-2

Enter length upto which you want to find multiples-13

10

12

14

16

18

20

22

24

26

>>>

Program 12. To count the number of vowels in a user entered string.

Program 13. To print the words starting with a particular alphabet in a user entered string.

Program 14. To print the number of occurrences of a given alphabet in a given string.

# Python Program to Count Occurrence of an alphabate in a String

string = input("Enter any String: ")

char = input("Enetr any alphabate to count its occurrence: ")


count = 0

for i in range(len(string)):

if(string[i] == char):

count = count + 1

print("Total Occurrence count of", char, " in string is = ",count)

Output:

Enter any String: "practical file for class 11 informatics practices term 1"

Enetr any alphabate to count its occurrence: "i"

('Total Occurrence count of', 'i', ' in string is = ', 5)

>>>

Enter any String: "practical file for class 11 informatics practices term 1"

Enetr any alphabate to count its occurrence: "z"

('Total Occurrence count of', 'z', ' in string is = ', 0)

>>>

Program 15. Create a dictionary to store names of states and their capitals.

'''Python Program to create a dictionary to

store names of states and their capitals.'''

states = dict()

no_of_states = int(input("Enter the number of states :"))

for i in range(no_of_states):

state_name = input("Enter name of state :")

state_capital = input("Enter capital of state :")

states[state_name] = state_capital

print("Dictionary is created :",states)

name = input("Enter the name of state to display capital:")

print(states[name])

Output:
Enter the number of states :3

Enter name of state :"UTTAR PRADESH"

Enter capital of state :"LUCKNOW"

Enter name of state :"UTTRAKHAND"

Enter capital of state :"DEHRADUN"

Enter name of state :"PUNJAB"

Enter capital of state :"CHANDIGARH"

('Dictionary is created :', {'PUNJAB': 'CHANDIGARH', 'UTTRAKHAND': 'DEHRADUN', 'UTTAR PRADESH':


'LUCKNOW'})

Enter the name of state to display capital:"PUNJAB"

CHANDIGARH

>>>

Program 16. Create a dictionary of students to store names and marks obtained in 5 subjects.

'''Python Program to Create a dictionary of students

to store names and marks obtained in 5 subjects.'''

#Empty Dictionary

students = dict()

no_of_student = int(input("Enter number of students :"))

for i in range(no_of_student):

std_name = input("Enter names of student :")

marks= []

for j in range(5):#Range for 5 subjects

mark = int(input("Enter marks :"))

marks.append(mark)

students[std_name] = marks

print("Dictionary of student created :")

print(students)

Output:
Enter number of students :3

Enter names of student :"Amit"

Enter marks :67

Enter marks :78

Enter marks :78

Enter marks :98

Enter marks :87

Enter names of student :"Sumit"

Enter marks :56

Enter marks :67

Enter marks :89

Enter marks :98

Enter marks :87

Enter names of student :"Neetu"

Enter marks :88

Enter marks :78

Enter marks :79

Enter marks :67

Enter marks :87

Dictionary of student created :

{'Amit': [67, 78, 78, 98, 87], 'Neetu': [88, 78, 79, 67, 87], 'Sumit': [56, 67, 89, 98, 87]}

>>>

You might also like