Professional Documents
Culture Documents
Program 1
Program 1
avg=(sub1+sub2+sub3+sub4+sub5)/5
#printing average
if(avg>=90):
print("Grade: A")
print("Grade: B")
print("Grade: C")
print("Grade: D")
else:
print("Grade: F")
Output:
Grade: B
>>>
Program 2. To find the sale price of an item with a given cost and discount (%).
discount=cost_price*discount_In_Percentage/100
saleing_price=cost_price-discount
print("Discount: ",discount)
Output:
Enter discount % : 10
Discount: 56.0
>>>
#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);
def area_circle(r):
area2=float(3.14*r*r);
def area_rectangle(a,b):
area3=float(a*b);
def area_triangle(x,y):
area4=float((x*y)/2);
peri1=float(4*a);
def peri_circle(r):
peri2=float(2*3.14*r);
def peri_triangle(a,b):
hypotenuse=float(math.sqrt(a*a+b*b))
peri3=float(a+b+hypotenuse)
def peri_rectangle(a,b):
peri4=float(2*(a+b))
area_square(side)
print()
peri_square(side)
area_circle(radius)
peri_circle(radius)
area_rectangle(length,breadth)
peri_rectangle(length,breadth)
area_triangle(base,height)
peri_triangle(base,height)
Output:
>>>
# Calcualtion
simple_interest = (principal*time*rate)/100
# Displaying result
Output:
Enter time: 5
Enter rate: 12
>>>
Program 5.To calculate profit-loss for a given Cost and Sell Price.
if cp==sp:
else:
if sp>cp:
print("Profit of ",sp-cp)
else:
print("Loss of ",cp-sp)
Output:
Profit of 48.0
>>>
No Profit No Loss
>>>
>>>
r = R/(12*100)
emi = p * r * ((1+r)**n)/((1+r)**n - 1)
Output:
>>>
print("GST = ",end='')
print(GST_percent,end='')
print("%")
Output:
GST = 3.1884057971014492%
>>>
mylist = []
for n in range(number):
mylist.append(element)
sorted_list = sorted(mylist)
'''
Output:
Enter element 34
Enter element 45
Enter element 23
Enter element 32
Enter element 65
Enter element 56
>>>
Program 10.1 To find the sum of squares of the first 100 natural numbers.
sum = 0
Output:
>>>
Program 10.2 Python Program to find the sum of square of given number.
number = int(input("Enter any number : "))
sum = 0
Output:
Sum of squares is : 30
>>>
Sum of squares is : 14
>>>
print(i*num)
Output:
10
15
20
>>>
10
12
14
16
18
20
22
24
26
>>>
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.
for i in range(len(string)):
if(string[i] == char):
count = count + 1
Output:
Enter any String: "practical file for class 11 informatics practices term 1"
>>>
Enter any String: "practical file for class 11 informatics practices term 1"
>>>
Program 15. Create a dictionary to store names of states and their capitals.
states = dict()
for i in range(no_of_states):
states[state_name] = state_capital
print(states[name])
Output:
Enter the number of states :3
CHANDIGARH
>>>
Program 16. Create a dictionary of students to store names and marks obtained in 5 subjects.
#Empty Dictionary
students = dict()
for i in range(no_of_student):
marks= []
marks.append(mark)
students[std_name] = marks
print(students)
Output:
Enter number of students :3
{'Amit': [67, 78, 78, 98, 87], 'Neetu': [88, 78, 79, 67, 87], 'Sumit': [56, 67, 89, 98, 87]}
>>>