Term 1 - IP-G11 - Record Book Programs
Term 1 - IP-G11 - Record Book Programs
Grade XI
IP - Practical Record Programs & Guidelines
INSTRUCTIONS
A. Python Programs
1. The Python program has to be written on the right page [ruled lines]
2. The output is to be shown on the left side of the book in a box [blank page]
3. Program No. is to be mentioned at the top of the page.
4. One single program is to be written on one page.
PROGRAM 1-
Program to input percentage marks of a student and find the grade as per following criterion:
Marks Grade
>=90 A
75-90 B
60-75 C
Below 60 D
Code:
a=float(input('Enter the percentage marks:'))
if a>=90:
print('The student has got an A grade')
elif a>=75 and a<90:
print('The student has got a B grade')
elif a>=60 and a<75:
print('The student has got a C grade')
else:
print('The student has got a D grade')
Output :
Enter the percentage marks:76
The student has got a B grade
PROGRAM 2-
Program to find sale price of an item with given cost and discount (%).
The discount rates are:
Amount Discount
0-5000 5%
5000-15000 12%
15000-25000 20%
above 25000 30%
Code:
amt = int(input("Enter Sale Amount: "))
if(amt>0):
if amt<=5000:
disc = amt*0.05
elif amt<=15000:
disc=amt*0.12
elif amt<=25000:
disc=0.2 * amt
else:
disc=0.3 * amt
print("Discount : ",disc)
print("Net Pay : ",amt-disc)
else:
print("Invalid Amount")
Output:
Enter Sale Amount: 4500
Discount : 225.0
Net Pay : 4275.0
PROGRAM 3-
Program to display a menu for calculating area of circle or perimeter of a circle.
Code:
radius = float(input(“Enter radius of the circle:”))
print(“1. Calculate Area”)
print(“2. Calculate Perimeter”)
choice = int(input(“Enter your choice(1 or 2):”))
if choice == 1:
area = 3.14 * radius * radius
print(“Area of circle with radius”, radius, “is”, area)
else :
perim = 2 * 3.14159 * radius
print(“Perimeter of circle with radius”, radius, “is”, perim)
Output:
Enter radius of the circle:5
1. Calculate Area
2. Calculate Perimeter
Enter your choice(1 or 2): 1
Area of circle with radius 5.0 is 78.5
PROGRAM 4-
Accept principal amount, time and rate of interest and find Simple Interest.
Code:
prin = int(input( "Enter Principal Amount : "))
rate = int(input( "Enter Rate : "))
time = int(input( "Enter Time : "))
SI = (P * R * T) / 100
print("Simple interest is", SI)
Output:
Enter Principal Amount : 1000
Enter Rate : 5
Enter Time : 1
Simple interest is 50.0
PROGRAM 5-
Program to calculate profit-loss for given Cost and Selling Price.
Code:
cp=float(input("Enter the cost price :"))
sp=float(input("Enter the selling price :"))
if sp>cp:
print("Profit is : ", sp-cp)
elif sp<cp:
print("Loss is : ", cp-sp)
else:
print("No profit or Loss")
Output:
Enter the cost price :1000
Enter the selling price :300
Loss is : 700.0
PROGRAM 6-
Accept a number and print the factorial.
Code:
n=int(input("Enter number:"))
fact=1
while(n>0):
fact=fact*n
n=n-1
print("Factorial of the number is: ")
print(fact)
Output:
Enter number:5
Factorial of the number is:
120
PROGRAM 7-
Program to find the largest number among the three input numbers
Code:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
Output :
Enter first number: 65
Enter second number: 78
Enter third number: 95
The largest number is 95.0
PROGRAM 8-
Program to find the largest and smallest numbers in a list.
Code-
num=[]
for i in range(10):
n=int(input("Enter a number :"))
num.append(n)
print("Given list is : :", num)
highest=max(num)
lowest=min(num)
print("Highest number is :",highest)
print("Lowest number is :",lowest)
Output:
Enter a number :12
Enter a number :11
Enter a number :15
Enter a number :23
Enter a number :34
Enter a number :45
Enter a number :2
Enter a number :33
Enter a number :78
Enter a number :43
Given list is : : [12, 11, 15, 23, 34, 45, 2, 33, 78, 43]
Highest number is : 78
Lowest number is : 2
PROGRAM 9-
Program to count the number of even and odd numbers from a series of numbers n1 to n2.
Code:
count_odd = 0
count_even = 0
n1=int(input("enter the 1st number :"))
n2=int(input("enter the 1st number :"))
for x in range(n1,n2+1):
if not x % 2:
count_even+=1
else:
count_odd+=1
print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)
Output :
enter the 1st number : 10
enter the 1st number :100
Number of even numbers : 46
Number of odd numbers : 45
PROGRAM 10-
Program to find the sum of the first n natural numbers.
Code-
n=int(input("Enter a number: "))
sum1 = 0
while(n > 0):
sum1=sum1+n
n=n-1
print("The sum of first n natural numbers is",sum1)
Output-
Enter a number: 10
The sum of first n natural numbers is 55
PROGRAM 11-
Program to print the first ‘n’ multiples of given number.
Code:
n=int(input("Enter the number to print the tables for:"))
a=int(input("Enter the last number:"))
for i in range(a+1):
print(n,"x",i,"=",n * i)
Output:
Enter the number to print the tables for:6
Enter the last number:10
6x0=0
6x1=6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60
PROGRAM 12-
To count the number of vowels in user entered string.
Code:
a=input("Enter string :")
b=a.lower()
vowels=0
for i in b:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
vowels=vowels+1
print("Number of vowels are:")
print(vowels)
Output-
Enter string :Welcome to India
Number of vowels are:
7
PROGRAM 13-
To print the words starting with a particular alphabet in a user entered string.
Code-
text=input("Enter a string :")
a=input("Enter an alphabet : ")
w=text.split()
for i in w:
if i[0]==a:
print(i)
Output-
Enter a string :The sun rises in the east
Enter an alphabet : e
east
PROGRAM 14-
Program to Count the number of occurrences of an item in a list
Code:
A=eval(input("Enter list: "))
num=eval(input("Enter the number:"))
count=0
for i in A:
if num==i:
count+=1
if count==0:
print("Item is not in list")
else:
print("Count of item - ",count)
Output-
Enter list: 23,34,56,1,12,67,1,23,12,13,12,67
Enter the number: 12
Count of item - 3
PROGRAM 15-
Create a dictionary to store names of states and their capitals.
Code-
states=dict()
n=int(input("How many states are there ? "))
for i in range(n):
s=input("Enter the name of the state :")
c=input("Enter the capital :")
states[s]=c
print("Created dictionary : ", states)
Output-
How many states are there ? 3
Enter the name of the state :Bihar
Enter the capital :Patna
Enter the name of the state :Rajasthan
Enter the capital :Jaipur
Enter the name of the state :West Bengal
Enter the capital :Kolkata
Created dictionary : {'Bihar': 'Patna', 'Rajasthan': 'Jaipur', 'West Bengal': 'Kolkata'}
PROGRAM 16-
Create a dictionary of students to store names and marks obtained in 5 subjects.
Code-
students=dict()
n=int(input("Enter the number of students :"))
for i in range(n):
sname=input("Enter name of the student :")
marks=[]
for j in range(5):
mark=float(input("Enter marks :"))
marks.append(mark)
students[sname]=marks
print("Created dictionary is :", students)
Output-
Enter the number of students :3
Enter name of the student :Arya
Enter marks :23
Enter marks :22
Enter marks :20
Enter marks :18
Enter marks :15
Enter name of the student :Tina
Enter marks :20
Enter marks :22
Enter marks :25
Enter marks :24
Enter marks :25
Enter name of the student :Brian
Enter marks :16.5
Enter marks :18
Enter marks :17
Enter marks :20
Enter marks :19
Created dictionary is : {'Arya': [23.0, 22.0, 20.0, 18.0, 15.0], 'Tina': [20.0, 22.0, 25.0, 24.0, 25.0],
'Brian': [16.5, 18.0, 17.0, 20.0, 19.0]}
PROGRAM 17-
To print the highest and lowest values in the dictionary.
Code-
scores={'Rahul':190,'Gokul':295,'Priya':110,'Varsha':320}
highest=max(scores,key=scores.get)
h=max(scores.values())
print("Highest score is for:", highest,"scoring",h)
lowest=min(scores,key=scores.get)
l=min(scores.values())
print("Highest score is for:", lowest,"scoring",l)
Output-
Highest score is for: Varsha scoring 320
Highest score is for: Priya scoring 110