I Puc - 24 Python Programs
I Puc - 24 Python Programs
# Calculating area
area = length * breadth
# Calculating perimeter
perimeter = 2 * (length * breadth)
# Displaying results
print("Area of rectangle = ", area)
print("Perimeter of rectangle = ", perimeter)
A4) Write a Python program to calculate the amount payable if money has
been lent on simple interest. Principal or money lent = P, Rate of interest =
R% per annum and Time = T years.
Then Simple Interest (SI) = (P x R x T)/ 100.
Amount payable = Principal + SI.
P, R and T are given as input to the program.
# Calcualtion
simple_interest = (principal*time*rate)/100
# Displaying result
print('Simple interest is: ',simple_interest)
Chapter 6 : Flow of Control
A5) Write a Python program to find largest
among three numbers.
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
smallest = 0
largest = 0
for a in range(0,5):
x = int(input("Enter the number: "))
if a == 0:
smallest = largest = x
if(x < smallest):
smallest = x
if(x > largest):
largest = x
print("The smallest number is",smallest)
print("The largest number is ",largest)
A8) Write a python program to find the grade of a student when grades are
allocated as given in the table below. Percentage of Marks Grade
Above 90% A
80% to 90% B
70% to 80% C
60% to 70% D
Below 60% E
Percentage of the marks obtained by the student is input to the program.
for i in range(rows,0,-1):
for j in range(1,i+1):
#print the number from 1 to i+1
print(j, end=" ")
Chapter 7 : Functions
B1) Write a program that uses a user defined function that accepts name
and gender (as M for Male, F for Female) and prefixes Mr/Ms on the
basis of the gender.
#Count number of words (Assume that each word is separated by one space)
totalSpace = 0
for b in userInput:
if b.isspace():
totalSpace += 1
def convertToTitle(string):
titleString = string.title();
print("The input string in title case is:",titleString)
B7) Write a python program to find the number of times an element occurs
in the list.
#defining a list
list1 = [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
name = tuple()
#Create empty tuple 'name' to store the values
n = int(input("How many names do you want to enter?: "))
for i in range(0, n):
num = input("> ")
#it will assign emailid entered by user to tuple 'name'
name = name + (num,)
myStr="2nd PU Course"
print("The input string is:",myStr)
myDict=dict()
for character in myStr:
if character in myDict:
myDict[character]+=1
else:
myDict[character]=1
print("The dictionary created from characters of the string is:")
print(myDict)
B12b) Create a dictionary with the roll number, name and marks of n
students in a class and display the names of students who have marks
above 75.