0% found this document useful (0 votes)
19 views12 pages

Class 11 - Cs - Record Model Exp - 13-20

The document outlines various Python programming experiments for a Class XI Computer Science curriculum. Each experiment includes an aim, algorithm, program code, and output, covering topics such as calculating simple interest, area of shapes, OTP generation, energy calculation, checking for duplicates in tuples, and working with dictionaries. All programs successfully execute and demonstrate fundamental programming concepts and functions.

Uploaded by

cocmentortn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views12 pages

Class 11 - Cs - Record Model Exp - 13-20

The document outlines various Python programming experiments for a Class XI Computer Science curriculum. Each experiment includes an aim, algorithm, program code, and output, covering topics such as calculating simple interest, area of shapes, OTP generation, energy calculation, checking for duplicates in tuples, and working with dictionaries. All programs successfully execute and demonstrate fundamental programming concepts and functions.

Uploaded by

cocmentortn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CLASS : XI RECORD MODEL SUBJECT: COMPUTER SCIENCE

EXPT NO: 13 CALCULATING SIMPLE INTEREST USING FUNCTION

Aim:

To write a python program to calculate the simple interest using functions.

Algorithm:

 Start the program


 Define the Function:
The simpleInterest function is defined with default values for time (2 years) and rate
(10% or 0.10). The function calculates the simple interest using the formula:
Simple Interest = principal × time × rate
 Call the Function: The program calls the simpleInterest function multiple times with different
values for principal, time, and rate to demonstrate different scenarios. Each call displays the
computed simple interest.
 Stop the program

Program:

def simpleInterest(principal,time=2,rate=0.10):

return(principal*time*rate)

print(simpleInterest(6100,1))

print(simpleInterest(5000,rate=0.05))

print(simpleInterest(5000,3,0.12))

print(simpleInterest(time=4,principal=5000))

Output :

610.0

500.0

1800.0

2000.0

Result:

Hence, the program was successfully executed.


EXPT NO: 14 PROGRAM TO CALCULATE THE AREA OF CIRCLE, RECTANGLE &
TRIANGLE,

Aim:

To write a python program to calculate the area of circle, rectangle & triangle,

Algorithm:

 Start the program


 Define functions to calculate the area of a circle, rectangle, and triangle.
 Show a menu and ask for the user's choice.
 Based on the choice, ask for necessary inputs, call the appropriate function, and display the
result.
 Handle invalid input gracefully.
 Stop the program.

Program:

# Function to calculate the area of a circle

def area_of_circle(radius):

pi = 3.14159

return pi * radius * radius

# Function to calculate the area of a rectangle

def area_of_rectangle(length, width):

return length * width

# Function to calculate the area of a triangle

def area_of_triangle(base, height):

return 0.5 * base * height

def main():

print("Choose the shape to calculate the area:")

print("1. Circle")

print("2. Rectangle")

print("3. Triangle")
choice = int(input("Enter your choice (1/2/3): "))

if choice == 1:

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

print("Area of the circle is:", area_of_circle(radius))

elif choice == 2:

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

width = float(input("Enter the width of the rectangle: "))

print("Area of the rectangle is:", area_of_rectangle(length, width))

elif choice == 3:

base = float(input("Enter the base of the triangle: "))

height = float(input("Enter the height of the triangle: "))

print("Area of the triangle is:", area_of_triangle(base, height))

else:

print("Invalid choice! Please choose 1, 2, or 3.")

# Calling the main function to execute the program

if __name__ == "__main__":

main()

Result: Hence, the program was successfully executed.


EXPT NO: 15 OTP GENERATOR USING RANDOM MODULE

Aim:

To write a python program to generate patterns.

Algorithm:

- Start the program


- Import the random module for generating random numbers.
- Define the generate_otp function to generate a random OTP.
- Get the desired OTP length from the user (default is 6).
- Call the function to generate the OTP and display it.
- Stop the program

Program:

import random

# Function to generate OTP

def generate_otp(length=6):

otp = ""

for i in range(length):

otp = otp+ str(random.randint(0, 9)) # Generate a random digit and add to OTP

return otp

# Main program

length = int(input("Enter the length of OTP (default is 6): "))

otp = generate_otp(length)

print("Your OTP is:",otp)

Output:
Enter the length of OTP (default is 6): 6
Your OTP is: 434792

Result: Hence, the program was successfully executed.


EXPT NO: 16 FINDING THE MASS OF THE OBJECT

Aim:

To write a python program that accepts the mass of an object and determines its energy.

Algorithm:

- Start the program


- Input: Prompt the user to enter the mass m (in kilograms).
- Set constant: Define the speed of light, c = 3×108
- Calculate Energy: Apply Einstein's equation , E=mc2, where: m is the mass entered by the user,
- c is the speed of light.
- Output: Print the calculated energy E in joules.
- Stop the program

Program:

import math

m=float(input("Enter Mass:"))

c=3*pow(10,8)

e=m*c*c

print("Equivalent Energy:",e,"Joule ")

Output:

Enter Mass:8.95

Equivalent Energy: 8.055e+17 Joule

Result:

Hence, the program was successfully executed.


EXPT NO: 17 CHECKING DUPLICATE ELEMENT PRESENT IN TUPLE OR NOT.

Aim:

To write a python program to check if a tuple contains any duplicate elements.

Algorithm:

 Start the program.


 Input: Prompt the user to enter a tuple tup.
 Loop through elements: For each element el in the tuple:
 Check if the element el appears more than once in the tuple using count ().
 Check for duplicates: If any element appears more than once, print "Contains duplicate
elements" and exit the loop.
 Output: If a duplicate is found, print the message and stop further checking.
 Stop the program

Program:

tup=eval(input("Enter the tuple:"))

for el in tup:

if tup.count(el)>1:

print("Contains duplicate elements")

break

Output:

Enter the tuple:6,7,12,13,11,13,8,13

Contains duplicate elements

Result:

Hence, the program was successfully executed.


EXPT NO: 18 FINDING THE STUDENT IN A TUPLE

Aim:

To write a python program to input the names of n students and store them in a tuple. Also,
input a name from the user and find if this student is present in the tuple or not.

Algorithm:

 Start the program.


 Input: Ask the user to input the number of students, n.
 Loop: For n iterations:
 Prompt the user to enter the name of each student.
 Append the student's name to a list lst.
 Create Tuple: Convert the list lst to a tuple ntuple.
 Search Name: Prompt the user to enter a name to search for, nm.
 Check for Existence: If nm exists in ntuple, print that the name exists in the tuple.
 Else: If nm does not exist in ntuple, print that the name does not exist in the tuple.
 Stop the program

Program:

lst=[]

n=int(input("How many students?"))

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

name=input("Enter the name of the student" +str(i)+ ":")

lst.append(name)

ntuple=tuple(lst)

nm=input("Enter the name to be searched for :")

if nm in ntuple:

print(nm,"exist in the tuple")

else:

print(nm,"does not exist in the tuple")


Output:

How many students?5

Enter the name of the student1:Ananya

Enter the name of the student2:Anusha

Enter the name of the student3:Kirat

Enter the name of the student4:Kyle

Enter the name of the student5:Suji

Enter the name to be searched for :Suji

Suji exist in the tuple

Result:

Hence, the program was successfully executed.


EXPT NO: 19 DISPLAY THE NAMES OF THE STUDENTS WHO HAVE SCORED MARKS
ABOVE 75 USING DICTIONARIES

Aim:

To write a python program to 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.

Algorithm:

 Start the program.


 Input: Ask the user for the number of students, n.
 Initialize Dictionary: Create an empty dictionary stu to store student details.
 Loop: For i from 1 to n:
o Prompt the user to enter the details for each student (roll number, name, marks).
o Store the student details (roll number, name, and marks) in a dictionary d.
o Create a unique key (e.g., "stu1", "stu2", etc.) and add the student details to the
stu dictionary using this key.
 Display Students with Marks > 75:
o Print the heading "Student with mark > 75 are".
o Loop through all students in the stu dictionary:
 For each student, check if their marks are greater than or equal to 75.
 If yes, print the student's details.
 Stop the program

Program:

n=int(input("How many students?"))

stu={}

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

print("Enter the details of Student",(i))

rollno= int(input("Enter the Roll no:"))

name=input("Enter Name:")

marks=float(input("Marks:"))

d={"Roll_no:" : rollno,"name": name, "Marks" : marks}

key="stu" + str(i)

stu[key]=d

print("Student with mark > 75 are")

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

key="stu" + str(i)

if stu[key]["Marks"] >=75:

print(stu[key])
Output:

How many students?4

Enter the details of Student 1

Enter the Roll no:101

Enter Name:Rathi

Marks:78

Enter the details of Student 2

Enter the Roll no:102

Enter Name:Bala

Marks:98

Enter the details of Student 3

Enter the Roll no:103

Enter Name:Zulfy

Marks:65

Enter the details of Student 4

Enter the Roll no:104

Enter Name:Sara

Marks:78

Student with mark > 75 are

{'Roll_no:': 101, 'name': 'Rathi', 'Marks': 78.0}

{'Roll_no:': 102, 'name': 'Bala', 'Marks': 98.0}

{'Roll_no:': 104, 'name': 'Sara', 'Marks': 78.0}

Result:

Hence, the program was successfully executed.


EXPT NO: 20 CREATE A NEW DICTIONARY USING COMMON KEYS OF OTHER
DICTIONARY

Aim:

To write a python program to create a third dictionary from two dictionaries having some
common keys, in ways so that the values of common keys are added in the third dictionary.

Algorithm:

 Start the program.


 Initialize Dictionaries:
o Define dct1 and dct2 with key-value pairs.
 Copy dct1:
o Create a copy of dct1 called dct3.
 Update dct3:
o Update dct3 with the contents of dct2, adding all key-value pairs from dct2 to
dct3.
 Add Values for Common Keys:
o Loop through each key-value pair in dct1 and dct2:
 If the key exists in both dictionaries (dct1 and dct2), add their
corresponding values and update dct3 with the sum.
 Output:
o Print dct1, dct2, and the final dct3 after updating with the summed values.
 Stop the program

Program:

dct1={'1':100,'2':200,'3':300}

dct2={'1':100,'2':200,'5':400}

dct3=dict(dct1)

dct3.update(dct2)

for i,j in dct1.items():

for x,y in dct2.items():

if i==x:

dct3[i]=(j+y)

print("Two given dictionaries are : ")

print(dct1)

print(dct2)

print("The resultant dictionary")


print(dct3)

Output:

Two given dictionaries are :

{'1': 100, '2': 200, '3': 300}

{'1': 100, '2': 200, '5': 400}

The resultant dictionary

{'1': 200, '2': 400, '3': 300, '5': 400}

Result:

Hence, the program was successfully executed.

You might also like