0% found this document useful (0 votes)
154 views

List of Program For Practical File With Source Code

The document contains 18 programming problems and their solutions in Python. The problems cover a range of concepts like calculating average and grade, sale price with discount, perimeter and area of shapes, simple and compound interest, profit/loss calculation, EMI calculation, GST calculation, finding largest/smallest number in a list, sum of squares, printing multiples of a number, counting vowels in a string, printing words starting with an alphabet, creating and accessing dictionaries, finding highest and lowest values in a dictionary, counting character occurrences in a string, and printing a simple number triangle pattern. For each problem, the source code and output is provided.

Uploaded by

Willy Wonka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views

List of Program For Practical File With Source Code

The document contains 18 programming problems and their solutions in Python. The problems cover a range of concepts like calculating average and grade, sale price with discount, perimeter and area of shapes, simple and compound interest, profit/loss calculation, EMI calculation, GST calculation, finding largest/smallest number in a list, sum of squares, printing multiples of a number, counting vowels in a string, printing words starting with an alphabet, creating and accessing dictionaries, finding highest and lowest values in a dictionary, counting character occurrences in a string, and printing a simple number triangle pattern. For each problem, the source code and output is provided.

Uploaded by

Willy Wonka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

# Program – 1. Write a python program to find average and grade for given marks.

Source Code:-
mm=int(input("Enter the maximum marks:"))
eng=int(input("Enter the marks of English:"))
acc=int(input("Enter the marks of Accountancy:"))
bs=int(input("Enter the marks of Business Studies:"))
eco=int(input("Enter the marks of Economics:"))
ip=int(input("Enter the marks of Informatics Practices:"))
tot=eng+acc+bs+eco+ip
t_mm=mm*5
per=(tot/t_mm)*100
print("Average is:",per,"%")
if per>=91 and per<=100:
gr='A1'
elif per>=81 and per<=90:
gr='A2'
elif per>=71 and per<=80:
gr='B1'
elif per>=61 and per<=70:
gr='B2'
elif per>=51 and per<=60:
gr='C1'
elif per>=41 and per<=50:
gr='C2'
elif per>=33 and per<=40:
gr='D'
else:
gr="Invalid Grade"
print("The Grade is:",gr)

Output:-
# Program – 2. Write a python program to find the sale price of an item with a given
cost and discount (%).

Source Code:-
cost=float(input("Enter the cost : "))

dis_per=float(input("Enter the discount in % : "))

dis=cost*dis_per/100

sel_price=cost-dis

print("Cost Price : ",cost)

print("Discount: ",dis)

print("Selling Price : ",sel_price)

Output:-
# Program – 3. Write a python program to calculate perimeter/circumference and area
of shapes such as triangle, rectangle, square and circle.

Source Code:-
import math
side=float(input("Enter the side of square:"))
ar_sq=float(side*side)
print("Area of Square:",ar_sq)
peri=float(4*side);
print("Perimeter of square is:",peri)
print()
r=float(input("enter the radius of circle:"))
ar_ci=float(3.14*r*r)
print("Area of circile:",ar_ci)
per_ci=float(2*3.14*r);
print("Perimter of circle is:%.2f"%per_ci)
print()
l=float(input("enter the length of rectangle:"))
b=float(input("enter the breadth of rectangle:"))
ar_rect=float(l*b)
print("Area of rectangle is:",ar_rect)
per_rect=float(2*(l+b))
print("Area of rectangle is:",per_rect)
print()
ba=float(input("enter the base of right angled triangle:"))
h=float(input("enter the height of right angled triangle:"))
ar_tri=float(float((ba*h)/2))
print("Area of triangle is:",ar_tri)
hpt=float(math.sqrt(h*h+ba*ba))
peri_tri=float(h+ba+hpt)
print("Perimter of right angled triangle is:",peri_tri)
Output:-
# Program – 4. Write a program to calculate Simple and Compound interest.

Source Code:-
#input

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

r = float(input('Enter the rate of interest: '))

t = float(input('Enter the time duration: '))

#process

si = (p*r*t)/100

ci= p * ( (1+r/100)**t - 1)

#output

print('Simple interest is: %.2f' % (si))

print('Compound interest is: %.2f' %(ci))

Output:-
# Program – 5. Write a program to calculate profit-loss for a given Cost and Sell Price.

Source Code:-
cost = float(input("Enter the cost of the product: "))

sale_amt = float(input("Enter the Sales Amount: "))

#declare a variable to store profit and loss

amt=0

#Actual process to compute profit or loss

if(cost > sale_amt):

amt = cost - sale_amt

print("Total Loss Amount = ",amt)

elif(cost < sale_amt):

amt = sale_amt - cost

print("Total Profit =",amt)

else:

print("No Profit No Loss!!!")

Output:-
# Program – 6. Write a program to calculate EMI for Amount, Period and Interest.

Source Code:-
# driver code

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

r = float(input("Enter the rate of interest:"))

t = float(input("Enter the time:"))

#intereset

r = r / (12 * 100)

#total installments

t = t * 12

emi = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1)

print("Monthly EMI is= %.2f"%emi)

Output:-
# Program – 7. Write a program to calculate tax - GST

Source Code:-
op=float(input("Enter original Price:-"))

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

GST_amt = np - op

GST_per = ((GST_amt * 100) / op)

print("GST Rate = %.2f"%GST_per,"%")

print("GST Amount = ",GST_amt)

Output:-
# Program – 8. Write a program to find the largest and smallest numbers in a list.

Source Code:-
l= []

n = int(input("Enter the Number of List Elements: "))

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

ele = int(input("Please enter the Value of Element%d : " %i))

l.append(ele)

mx = mn = l[0]

for j in range(1, n):

if(mn > l[j]):

mn = l[j]

min_pos = j

if(mx < l[j]):

mx = l[j]

max_pos = j

print("The Smallest Element in the List is : ", mn)

print("The position of Smallest Element in the List is : ", min_pos)

print("The Largest Element in the List is : ", mx)

print("The position of Largest Element in the List is : ", max_pos)

Output:-
# Program – 9. Write a python program to find the third largest/smallest number in a
list.

Source Code:-
l = []
n = int(input("Enter the Number of List Elements: "))
for i in range(1, n + 1):
ele = int(input("Please enter the Value of Element%d : " %i))
l.append(ele)
large = l[0]
sec_large = l[0]
third_large = l[0]
for i in l :
if i > large:
third_large = sec_large
sec_large = large
large = i
elif i > sec_large :
third_large = sec_large
sec_large = i
elif i > third_large:
third_large = i
print("Third largest number of the list is:",third_large)

Output:-
# Program – 10. Write a program to find the sum of squares of the first 100 natural
numbers.

Source Code:-
sum1 = 0
for i in range(1, 101):
sum1 = sum1 + (i*i)
print("Sum of squares is : ", sum1)

Output:-
# Program – 11. Write a program to print the first ‘n’ multiples of a given number.

Source Code:-
#input

n = int(input("Enter the number to display multiples:"))

m = int(input("Enter the number to display n multiples:"))

#computing multiples

multip = range(n, (n * m) + 1, n)

print(list(multip))

Output:-
# Program – 12. Write a program to count the number of vowels in a user entered string.

Source Code:-
txt=input("Enter string:")

vowels=0

for i in txt:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):

vowels=vowels+1

print("Number of vowels are:",vowels)

Output:-
# Program – 13. Write a program to print the words starting with a particular alphabet in
a user entered string.

Source Code:-
txt=input("Enter the text:")

al=input("Enter alphabet to print the words:")

for i in txt.split():

if i.startswith(al):

print(i)

Output:-
# Program – 14. Create a dictionary of students to store names and marks obtained in 5
subjects.

Source Code:-
students={'Aksh':[34,46,48,33,47],'Bhavik':[44,45,48,43,42]}

print(students)

Output:-
# Program – 15. Create a dictionary to store names of states and their capitals.

Source Code:-
st={'Gujarat':'Ghandhinagar','Rajasthan':'Jaipur','Bihar':'Patna','Maharashtra':'Mumbai',\
‘Madhya Pradesh':'Bhopal'}

print(st)

Output:-
# Program – 16. Write a program to print the highest and lowest values in the
dictionary.

Source Code:-
my_dict = {'x':500, 'y':5874, 'z': 560}

key_max = max(my_dict.keys())

key_min = min(my_dict.keys())

print('Maximum Value: ',my_dict[key_max])

print('Minimum Value: ',my_dict[key_min])

Output:-
# Program – 17. Write a program to print the number of occurrences of a given alphabet
in a given string.

Source Code:-
# Python Program to Count Occurrence of a Character in a String

string = input("Please enter your own String : ")

char = input("Please enter your own Character : ")

count = 0

for i in range(len(string)):

if(string[i] == char):

count = count + 1

print("The total Number of Times ", char, " has Occurred = " , count)

Output:-
# Program – 18. Write a program to print Simple Number Triangle Pattern.

Pattern:
1
22
333
4444
55555

Source Code:-
rows = 6
for num in range(rows):
for i in range(num):
print(num, end=' ') # print number
# line after each row to display pattern correctly
print(' ')

Output:-

You might also like