0% found this document useful (0 votes)
14 views44 pages

Python Programming Lab Exercises

The document outlines a Python Programming Lab course at Mohamed Sathak College of Arts and Science for the academic year 2025-2026. It includes a bonafide certificate, an index of various programming exercises, and detailed descriptions of several Python programs covering topics such as temperature conversion, student grade systems, area calculations, and more. Each program is presented with its aim, code, output, and verification results.

Uploaded by

anvarehh
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)
14 views44 pages

Python Programming Lab Exercises

The document outlines a Python Programming Lab course at Mohamed Sathak College of Arts and Science for the academic year 2025-2026. It includes a bonafide certificate, an index of various programming exercises, and detailed descriptions of several Python programs covering topics such as temperature conversion, student grade systems, area calculations, and more. Each program is presented with its aim, code, output, and verification results.

Uploaded by

anvarehh
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

MOHAMED SATHAK COLLEGE

OF ARTS AND SCIENCE


SHOLINGANALLUR, CHENNAI 600119
AFFILIATED TO THE UNIVERSITY OF MADRAS

DEPARTMENT OF COMPUTER APPLICATIONS

SEMESTER – I (2025 – 2026)

PYTHON PROGRAMMING LAB – 120C11

NAME :
ROLL NO :
REGISTER NO :

1
MOHAMED SATHAK COLLEGE
OF ARTS AND SCIENCE
SHOLINGANALLUR, CHENNAI - 600119
AFFILIATED TO THE UNIVERSITY OF MADRAS

BONAFIDE CERTIFICATE
DEPARTMENT OF COMPUTER APPLICATIONS

REGISTER NO: ______________________________________

This is to certify that the bonafide record work done by ___________________________


is studying in MOHAMED SATHAK COLLEGE OF ARTS AND SCIENCE, during the
academic year 2025-2026.

Submitted for the practical examination held on _____________________________

Lecturer-In-Charge Head of the Department

Internal Examiner External Examiner

2
MOHAMED SATHAK COLLEGE OF ARTS AND SCIENCE
SHOLINGANALLUR, CHENNAI-600119.

INDEX

PAGE
[Link]. DATE TITLE SIGN
NO
Temperature Conversion Program(Celsius to
1.
Fahrenheit)
2. Student Grade System

Area of Triangle, Circle, Square and


3.
Rectangle
4. Fibonacci Series

5. Find factorial value using recursive functions

Count the number of Odd and Even


6.
numbers
Calculate the number of Lower case and
7.
Upper case letters
8. Given String is palindrome or not

9. Find the sum of all items in a dictionary

10. Program for Construct a number Pyramid

Program for read a file content and copy


11.
only the contents at odd lines into a new file
Create a turtle graphics window with
12.
specific size
13. Towers of Hanoi using Recursion

Create a menu driven Python program with


14.
dictionary for words and their meanings
15. Program to implement the Hangman Game

3
[Link] : 1
TEMPERATURE CONVERSION

AIM
To create a python program by using temperature conversion.

4
PROGRAM
ch=input("Enter your choice (F/C):")
if ch=='C' or ch=='c':
c=float(input("Enter the Celsius value:"))
f=(9/5*c)+32
print(c,"Celsius equals to",f,'Faherenheit')
if ch=='F' or ch=='f':
f=float(input("Enter the Faherenheit value:"))
c=(5/9*(f-32))
print(f,"Faherenheit equals to",c,'Celsius')
OUTPUT
Enter your choice (F/C):F
Enter the Faherenheit value:95
95.0 Faherenheit equals to 35.0 Celsius
Enter your choice (F/C):C
Enter the Celsius value:38
38.0 celsius equals to 100.4 Faherenheit

RESULT
Thus, the program was sucessfully verified.

5
[Link] : 2
STUDENT MARK LIST PROGRAM

AIM
To create a python program by using Student Mark List.

6
PROGRAM
studentname=input("Enter your name:")
print("Enter the 5 subject marks one by one:")
m1=int(input("subject1:"))
m2=int(input("subject2:"))
m3=int(input("subject3:"))
m4=int(input("subject4:"))
m5=int(input("subject5:"))
totmarks=m1+m2+m3+m4+m5
print(“Total Marks:”,totmarks)
percentage=totmarks/5
print("Percentage:",percentage)
if percentage>=80:
grade='A'
elif percentage>=70 and percentage<80:
grade='B'
elif percentage>=60 and percentage<70:
grade='C'
elif percentage>=40 and percentage<60:
grade='D'
else:
grade='E'
print("Grade:",grade)

7
OUTPUT
Enter your name:smbalaji
Enter the 5 subject marks one by one:
subject1:99
subject2:98
subject3:97
subject4:98
subject5:99
Total Marks:491
Percentage: 98.2
Grade: A

RESULT
Thus, the program was successfully verified.

8
[Link] : 3
FIND AREA OF TRIANGLE, RECTANGLE, CIRCLE,
SQUARE

AIM
To find a python program by using area of triangle, rectangle,circle, square

9
PROGRAM
#Program to Find Area
import math
#AREA OF TRIANGLE
print("\n\n AREA OF TRIANGLE \n")
a=int(input("Enter first side:"))
b=int(input("Enter second side:"))
c=int(input("Enter third side:"))
s=(a+b+c)/2
area=[Link](s*(s-a)*(s-b)*(s-c))
print("Area of the Triangle is:",area)
#AREA OF CIRCLE
PI=3.14
print("\n\nAREA OF CIRCLE \n")
r=float(input('Enter the radius of circle:'))
area=PI*r*r
print("Area of the circle is:",area)
#AREA OF SQUARE
print("\n\n AREA OF SQUARE \n")
s=int(input("Enter the square value:"))
area=s*s
print("Area of square is:",area)
#AREA OF RECTANGLE
print("\n\n AREA OF RECTANGLE \n")
h=int(input("Enter the height value:"))
w=int(input("Enter the width value:"))
area=h*w

10
print("Area of Rectangle is:",area)

OUTPUT
AREA OF TRIANGLE
Enter first side:5
Enter second side:6
Enter third side:7
Area of the Triangle is: 14.696938456699069
AREA OF CIRCLE
Enter the radius of circle:8
Area of the circle is: 200.96
AREA OF SQUARE
Enter the square value:5
Area of square is: 25
AREA OF RECTANGLE
Enter the height value:8
Enter the width value:5
Area of Rectangle is: 40

RESULT
Thus, the program was successfully verified.

11
[Link] : 4
TO DISPLAY THE FIRST NTERMS OF FIBONACCI SERIES

AIM
To display the first n terms of Fibonacci series by using Python program

12
PROGRAM
nterms=int(input("How many terms to be printed?"))
n1,n2=0,1
count=0
# To check if the number of terms is valid
if nterms<0:
print("Please enter a positive integer:")
elif nterms==1:
print("Fibonacci sequence upto nterms:")
print(n1)
else:
print("Fibonacci sequence are:")
while count<nterms:
print(n1)
nth=n1+n2
#update value
n1=n2
n2=nth
count+=1

13
OUTPUT
How many terms to be printed?10
Fibonacci sequence are:
0
1
1
2
3
5
8
13
21
34

RESULT
Thus, the program was successfully verified.

14
[Link] : 5
FACTORIAL USING RECURSION

AIM
To display factorial using recursion by using Python program

15
PROGRAM
#Factorial using recursion
def factorial(n):
if n==0:
return 1
else:
return n*factorial(n-1)
print(format("Factorial value using Recursion"))
n=int(input("Enter the number to find the factorial:"))
print("Factorial of",n,"is:",factorial(n))

OUTPUT

Factorial value using Recursion


Enter the number to find the factorial:5
Factorial of 5 is: 120

RESULT
Thus, the program was successfully verified.

16
[Link] : 6
COUNTING EVEN & ODD NUMBERS USING ARRAY

AIM
To display counting even & odd numbers using array by using Python program

17
PROGRAM
#Counting Even and Odd numbers in Array
import array as arr
n=[Link]('i',[1,2,3,4,5,6,7,8,8])
odd=0
even=0
for i in n:
if i%2==0:
even+=1
else:
odd+=1
print("Number of Even numbers in an Array:",even)
print("Number of Odd Numbers in an Array:",odd)

OUTPUT
Number of Even numbers in an Array: 5
Number of Odd Numbers in an Array: 4

RESULT
Thus, the program was successfully verified.

18
[Link] : 7
COUNTING NUMBER OF UPPER & LOWER CASE IN A
GIVEN STRING

AIM

To counting number of upper & lower case in a given string by using Python
program

19
PROGRAM
#COUNTING NUMBER OF UPPER & LOWER CASE IN A GIVEN STRING
str=input("Enter the string:")
upper=0
lower=0
for i in str:
if([Link]()):
upper=upper+1
elif([Link]()):
lower=lower+1
print("The upper case letters:",upper)
print("The lower case letters:",lower)

OUTPUT
Enter the string: Mohamed Sathak College of Arts and Science
The upper case letters: 5
The lower case letters: 31

RESULT
Thus, the program was successfully verified.

20
[Link] : 8
TO CHECK GIVEN STRING IS PALINDROME OR NOT

AIM
To check given string is palindrome or not by using Python program

21
PROGRAM
#TO CHECK GIVEN STRING IS PALINDROME OR NOT
string=input("Enter the string:")
str1=""
for i in string:
str1=i+str1
print("String is reverse order:",str1)
if (string==str1):
print("Given string is a Palindrome.")
else:
print("Given string is not a Palindrome.")

OUTPUT
Enter the string:madam
String is reverse order: madam
Given string is a Palindrome.
Enter the string:welcome
String is reverse order: emoclew
Given string is not a Palindrome.

RESULT
Thus, the program was successfully verified.

22
[Link] : 9 SUM OF ITEMS IN DICTIONARY

AIM
To create a python program by using sum of items in dictionary.

23
PROGRAM
count=int(input("Number of items in a dictionary:"))
numdictionary={}
for i in range(count):
value=int(input("Enter the value:"))
numdictionary[i]=value
print("The Dictionary is:",numdictionary)
sum=0
for i in [Link]():
sum=sum+numdictionary[i]
print("Sum of values in dictionary is:",sum)

OUTPUT
Number of items in a dictionary:5
Enter the value:8
Enter the value:9
Enter the value:6
Enter the value:7
Enter the value:5
The Dictionary is: {0: 8, 1: 9, 2: 6, 3: 7, 4: 5}
Sum of values in dictionary is: 35

RESULT
Thus, the program was successfully verified.

24
[Link] : 10
CONSTRUCT PATTERN USING NESTED LOOP

AIM
To create a python program by using construct pattern using nested loop

25
PROGRAM
#CONSTRUCT PATTERN USING NESTED LOOP
n=int(input("Enter the Number of Rows:"))
for i in range(n):
for j in range(i+1):
print(i+1,end="")
print()

OUTPUT
Enter the Number of Rows:9
1
22
333
4444
55555
666666
7777777
88888888
999999999

RESULT
Thus, the program was successfully verified.

26
[Link] : 11
PROGRAM TO READ A FILE CONTENT AND COPY
THE CONTENTS AT ODD LINES INTO A FILE

AIM
To create a python program to read a file content and copy the contents at odd
lines into a file.

27
PROGRAM
# Program for read a file content and copy only the contents at odd lines into a new file.
sourcefile= input("Enter source file name : ")
destinationfile=input("Enter destination file name : ")
sourcefile1 = open(sourcefile,'r')
destinationfile1=open(destinationfile,'w')
print("Source content")
line=[Link]()
writemode=1
while line!='':
print(line)
if writemode%2!=0:
[Link](line)
writemode +=1
line=[Link]()
[Link]()
[Link]()
destinationfile1=open(destinationfile,'r')
print("content of destination file after copy")
line=[Link]()
while line!='':
print(line) line=[Link]()
[Link]()

28
OUTPUT

[Link]
LINE1
LINE2
LINE3
LINE4
[Link]
LINE1
LINE3

RESULT
Thus, the program was successfully verified.

29
[Link] : 12
CREATE A TURTLE GRAPHICS WINDOW WITH
SPECIFIED SIZE

AIM
To create a turtle graphics window with specified size.

30
PROGRAM
#Create a turtle graphics window with specific size
import turtle
[Link](800,600)
[Link](255)
window=[Link]()
[Link]("Turtle Graphics Window")
turtle1=[Link]()
[Link]()
MoveLength=100
pensize=1
for i in range(0,10):
[Link]()
[Link](MoveLength)
[Link](90)
[Link]()
[Link](pensize+3)
[Link](MoveLength)
[Link](90)
[Link](pensize)
[Link]("red")
[Link](MoveLength+10)
[Link](90)
[Link](pensize+3)
[Link]("red")
[Link](MoveLength+10)

31
[Link](90)
MoveLength+=20

OUTPUT

RESULT
Thus, the program was successfully verified.

32
[Link] : 13
TOWERS OF HANOI USING RECURSION

AIM
To create a towers of HANOI using recursion.

33
PROGRAM
#Towers of Hanoi using Recursion
def hanoi(n, source, dest, rod):
if n==1:
print ("Move disk 1 from source",source,"to destination",dest)
return
hanoi(n-1, source, rod, dest)
print("Move Disk",n,"from source",source,"to destination",dest)
hanoi(n-1, rod, dest, source)
n=int(input("Enter number of Disk:"))
hanoi(n,'A','B','C')
OUTPUT
Enter number of Disk:3
Move disk 1 from source A to destination B
Move Disk 2 from source A to destination C
Move disk 1 from source B to destination C
Move Disk 3 from source A to destination B
Move disk 1 from source C to destination A
Move Disk 2 from source C to destination B
Move disk 1 from source A to destination B

RESULT
Thus, the program was successfully verified.

34
[Link] : 14 CREATE A MENU DRIVEN PYTHON PROGRAM
WITH DICTIONARY FOR WORDS AND THEIR
MEANINGS.

AIM
To create a menu driven python program with dictionary for words and their meanings.

35
PROGRAM

#Create a menu driven Python program with dictionary for words and their meanings.

def insertword(worddic,word,meaning):

worddic[word]=meaning

print("The word is Inserted")

def searchmeaning(worddic,word):

if word in [Link]():

print(word, " - ",worddic[word])

else:

print("The searching word is not exist")

worddic={}

print("1. Insert new word ")

print("2. Search the meaning ")

print("3. Exit")

choice=int(input("Enter your choice :"))

while choice==1 or choice==2:

if choice==1:

word=input("Enter the word to insert :").lower()

meaning=input("Enter the meaning of the word : ").lower()

insertword(worddic,word,meaning)

print("Dictionary :",worddic)

elifchoice==2:

if len(worddic)>0:

36
word=input("Enter the word to get meaning :").lower()

searchmeaning(worddic,word)

else:

print("No word to search, It is Empty")

exit;

print("\n \n [Link] new word")

print("\n 2. Search meaning")

print("\n 3. exit")

choice= int(input("Enter your choice :"))

print("Thank you for using dictionary")

Output

1. Insert new word

2. Search the meaning

3. Exit Enter your choice :2

No word to search, It is Empty

1. Insert new word

2. Search the meaning

3. Exit Enter your choice :1

Enter the word to insert :msc

Enter the meaning of the word : mohamed sathak college

The word is Inserted Dictionary : {'msc': 'mohamed sathak college'}

1. Insert new word

37
2. Search meaning

3. exit Enter your choice :1

Thank you for using dictionary

Enter the word to insert :dos

Enter the meaning of the word : disk operating system

The word is Inserted

Dictionary : {'msc': 'mohamed sathak college', 'dos': 'disk operating system'}

1. Insert new word

2. Search meaning

3. exit Enter your choice :1

Thank you for using dictionary

Enter the word to insert :dbms

Enter the meaning of the word : database management system

The word is Inserted

Dictionary : {'msc': 'mohamed sathak college', 'dos': 'disk operating system', 'dbms': 'database
management system'}

[Link] new word

[Link] meaning

3. exit

Enter your choice :2

Thank you for using dictionary

Enter the word to get meaning :msc msc - mohamed sathak college

1. Insert new word

2. 2. Search meaning

3. 3. exit

38
Enter your choice :1

Thank you for using dictionary

Enter the word to insert :ram

Enter the meaning of the word : random access memory

The word is Inserted Dictionary : {'msc': 'mohamed sathak college', 'dos': 'disk operating
system', 'ram': 'random access memory'}

1. Insert new word

2. Search meaning

3. exit

Enter your choice :3

Thank you for using dictionary

RESULT
Thus, the program was successfully verified.

39
[Link] : 15
HANGMAN PROBLEM

AIM
To create a HANGMAN PROBLEM by using python program.

40
PROGRAM

import time
import random
name = input("What is your name? ")
print("Hello, " + name, "Time to play hangman!")
print("")
[Link](1)
print( "Start guessing...")
[Link](0.5)
word = "computer"
guesses = ''
#determine the number of turns
turns = 10
while turns > 0:
# make a counter that starts with zero
failed = 0
# for every character in secret_word
for char in word:
# see if the character is in the players guess
if char in guesses:
# print then out the character
print (char,' ',end="")
else:
# if not found, print a dash
print ("_ ",end="")
# and increase the failed counter with one

41
failed += 1
# if failed is equal to zero
# print You Won
if failed == 0:
print ("You won",name)
# exit the script
break
# ask the user go guess a character
guess = input("guess a character:")
# set the players guess to guesses
guesses += guess
# if the guess is not found in the secret word
if guess not in word:
# turns counter decreases with 1 (now 9)
turns -= 1
# print wrong
print( "Wrong")
# how many turns are left
print ("You have", + turns, 'more guesses' )
# if the turns are equal to zero
if turns == 0:
# print "You Lose"
print( "You Lose,actual word is",word)

Output : 1

What is your name? Kalai


Hello, kalai Time to play hangman!
Start guessing…

42
_ _ _ _ _ _ _ _ guess a character:c
c _ _ _ _ _ _ _ guess a character:r
c _ _ _ _ _ _ r guess a character:p
c _ _ p _ _ _ r guess a character:e
c _ _ p _ _ e r guess a character:m
c _ m p _ _ e r guess a character:t
c _ m p _ t e r guess a character:o
c o m p _ t e r guess a character:u
c o m p u t e r You won kalai
Output - 2
What is your name? kalai
Hello, kalai Time to play hangman!
Start guessing…
_ _ _ _ _ _ _ _ guess a character:a
Wrong
You have 9 more guesses
_ _ _ _ _ _ _ _ guess a character:d
Wrong
You have 8 more guesses
_ _ _ _ _ _ _ _ guess a character:b
Wrong You have 7 more guesses
_ _ _ _ _ _ _ _ guess a character:f
Wrong
You have 6 more guesses
_ _ _ _ _ _ _ _ guess a character:i
Wrong You have 5 more guesses
_ _ _ _ _ _ _ _ guess a character:n
Wrong
You have 4 more guesses
_ _ _ _ _ _ _ _ guess a character:g
Wrong

43
You have 3 more guesses
_ _ _ _ _ _ _ _ guess a character:l
Wrong
You have 2 more guesses
_ _ _ _ _ _ _ _ guess a character:j
Wrong
You have 1 more guesses
_ _ _ _ _ _ _ _ guess a character:u
_ _ _ _ u _ _ _ guess a character:s
Wrong You have 0 more guesses
You Lose, actual word is computer

RESULT
Thus, the program was successfully verified.

44

You might also like