0% found this document useful (0 votes)
13 views34 pages

Python

Uploaded by

Kalai Arul
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)
13 views34 pages

Python

Uploaded by

Kalai Arul
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

GOVERNMENT ARTS AND SCIENCE COLLEGE

TIRUCHULI - 626 129

DEPARTMENT OF COMPUTER SCIENCE


MADURAI KAMARAJ UNIVERSITY PRACTICAL
EXAMINATIONS
NOVEMBER – 2025

RECORD NOTE BOOK

SCSPC3P-Python Programming LAB

Student Name

Register Number

Class II [Link]. (Computer Science)

Semester III

Month & Year NOVEMBER 2025


GOVERNMENT ARTS AND SCIENCE
COLLEGE
TIRUCHULI - 626 129

DEPARTMENT OF COMPUTER SCIENCE


MADURAI KAMARAJ UNIVERSITY PRACTICAL
EXAMINATIONS
NOVEMBER – 2025

BONAFIDE CERTIFICATE

This is to certify that this practical work titledPython Programming


LAB (SCSPC3P) is the bonafide work of
…………………………………………………… Register
Number…..……………………………. during the academic year 2025-2026.

Head of the Department Faculty In-charge

Submitted for Madurai Kamaraj University, Madurai - 625 021


practical examination held on ___/___/______at Government Arts and
Science College, Tiruchuli, Virudhunagar District – 626 129.

Internal Examiner External Examiner


INDEX

[Link] DATE CONTENT [Link] SIGNATURE

Program using variables, constants, I/O


1 statements in Python

2 Program using Operators in Python

3 Program using Conditional


Statements
4 Program using Loops.

5 Program using Jump Statements

6 Program using Functions

7 Program using Recursion

8 Program using Arrays

9 Program using Strings

10 Program using Modules

11 Program using Lists

12 Program using Tuples

13 Program using Dictionaries

14 Program for File Handling


[Link]. : 1 PROGRAM USING VARIABLES, CONSTANTS,
I/O STATEMENTS IN PYTHON Date:

AIM:

The aim of the program is to calculate the area of a circle using a constant value for pi and user

input for the radius.

ALGORITHM:

Step 1: Initialize a constant variable PI with the value 3.14159.

Step 2: Prompt the user to enter the radius of the circle.

Step 3: Read the input value and store it in a variable radius.

Step 4: Calculate the area of the circle using the formula area = PI * radius * radius.

Step 5: Display the calculated area of the circle.

CODING:

PI = 3.14159

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

area = PI * radius * radius

print("The area of the circle is:", area)


OUTPUT:
Enter the radius of the circle: 5

The area of the circle is: 78.53975

RESULT:
Thus the python program for using variables, constants, i/o statements was written executed and
the output was verified.
[Link]. : 2 PROGRAM USING OPERATORS IN PYTHON Date:

AIM:

The aim of the program is to perform basic arithmetic operations using operators in
Python.

ALGORITHM:

Step 1: Prompt the user to enter two numbers.

Step 2: Read the input values and store them in variables num1 and num2.

Step 3:Perform the following operations:

Addition: result = num1 + num2

Subtraction: result = num1 - num2

Multiplication: result = num1 * num2

Division: result = num1 / num2

Modulo: result = num1 % num2

Exponentiation: result = num1 ** num2

Step 4: Display the results of each operation.


CODING:

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

result = num1 + num2

print("Addition:", result)

result = num1 - num2

print("Subtraction:", result)

result = num1 * num2

print("Multiplication:",

result) result = num1 / num2

print("Division:", result)

result = num1 % num2

print("Modulo:", result)

result = num1 ** num2

print("Exponentiation:", result)
OUTPUT:

Enter the first number: 10

Enter the second number: 3

Addition: 13.0

Subtraction: 7.0

Multiplication: 30.0

Division: 3.3333333333333335

Modulo: 1.0

Exponentiation: 1000.0

RESULT:
Thus the python program for using arithmetic operators was written executed and the output was
verified.
[Link]. : 3 PROGRAM USING CONDITIONAL STATEMENTS Date:

AIM:

The aim of the program is to determine whether a given number is positive, negative, or
zero using conditional statements in Python.

ALGORITHM:

Step 1: Prompt the user to enter a number.

Step 2: Read the input value and store it in a variable num.

Step 3: Use conditional statements to check the value of num:

Step 4: If num is greater than 0, display "Positive number".

Step 5: If num is less than 0, display "Negative number".

Step 6: If num is equal to 0, display "Zero".

Step 7: End the program.


CODING:

num = float(input("Enter a number: "))

if num > 0:

print("Positive number")

elif num < 0:

print("Negative number")

else:

print("Zero")

OUTPUT:

Enter a number: 5

Positive number

Enter a number: -2

Negative number

Enter a number: 0

Zero

RESULT:
Thus the python program for using conditional statements was written executed and the output was
verified.
[Link]. : 4 PROGRAM USING LOOPS Date:

AIM:

The aim of the program is to display the numbers from 1 to 10 using a loop in Python.

ALGORITHM:

Step 1: Initialize a variable num with the value 1.

Step 2: Use a loop to iterate from num to 10 (inclusive).

Step 3: Print the value of num.

Step 4: Increment num by 1.

Step 5: End the loop.

CODING:

num = 1

while num <= 10:

print(num)

num += 1
OUTPUT:

10

RESULT:
Thus the python program for using loops was written executed and the output was verified.
[Link]. : 5 PROGRAM USING JUMP STATEMENTS Date:

AIM:

The aim of the program is to demonstrate the use of jumping statements (break and continue) in

Python.

ALGORITHM:

Step 1: Use a loop to iterate through the numbers from 1 to 10 (inclusive).

Step 2: Inside the loop, check if the current number is divisible by 3.

Step 3: If the number is divisible by 3, use the continue statement to skip the remaining code in the loop
and move to the next iteration.

Step 4: If the number is not divisible by 3, print the number.

Step 5: Check if the current number is equal to 7.

Step 6: If the number is equal to 7, use the break statement to exit the loop.

Step 7: End the loop.


CODING:

for num in range(1, 11):

if num % 3 == 0:

continue

print(num)

if num =7:

break

OUTPUT:

RESULT:
Thus the python program for using Jump Statements was written executed and the output was
verified.
[Link]. : 6 PROGRAM USING FUNCTIONS Date:

AIM:

The aim of the program is to create a function that adds two numbers in Python.

ALGORITHM:

Step 1: Define a function named add_numbers that takes two parameters num1 and num2.

Step 2: Inside the add_numbers function, add num1 and num2 and store the result in a variable

sum.

Step 3: Return the value of sum.

Step 4: Prompt the user to enter two numbers.

Step 5: Read the input values and store them in variables n1 and n2.

Step 6: Call the add_numbers function, passing n1 and n2 as arguments, and store the result in a

variable result.

Step 7:Display the sum of the two numbers.


CODING:

def add_numbers(num1, num2):

sum = num1 + num2

return sum

n1 = float(input("Enter the first number: "))

n2 = float(input("Enter the second number: "))

result = add_numbers(n1, n2)

print("Sum:", result)

OUTPUT:

Enter the first number: 5

Enter the second number: 3

Sum: 8.0

RESULT:
Thus the python program for using Functions was written executed and the output was verified.
[Link]. : 7 PROGRAM USING RECURSION Date:

AIM:

The aim of the program is to create a function that calculates the factorial of a given
number in Python.

ALGORITHM:

Step 1: Define a function named factorial that takes a single parameter num.

Step 2: Inside the factorial function, initialize a variable result with the value 1.

Step 3: Use a for loop to iterate from 1 to num (inclusive).

Step 4: Multiply result by the current value of the loop variable.

Step 5: Return the value of result.

Step 6: Prompt the user to enter a number.

Step 7: Read the input value and store it in a variable n.

Step 8: Call the factorial function, passing n as an argument, and store the result in a variable

fact.

Step 9: Display the calculated factorial value.


CODING:

def factorial(num):

result = 1

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

result *= i

return result

n = int(input("Enter a number: "))

fact = factorial(n)

print("Factorial of", n, "is", fact)

OUTPUT:

Enter a number: 5

Factorial of 5 is

120

RESULT:
Thus the python program for using Recursion was written executed and the output was verified.
[Link]. : 8 PROGRAM USING ARRAYS Date:

AIM:

The aim of the program is to demonstrate the use of arrays in Python by storing and
manipulating a list of numbers.

ALGORITHM:

Step 1: Create an array/list to store numbers.

Step 2: Prompt the user to enter the size of the array.

Step 3: Read the input value and store it in a variable size.

Step 4: Use a loop to iterate size number of times.

Step 5: Inside the loop, prompt the user to enter a number and append it to the array.

Step 6: Calculate the sum and average of the numbers in the array.

Step 7: Initialize variables sum and average with the value 0.

Step 8: Use a loop to iterate through each element of the array.

Step 9: Add each element to the sum variable.

Step 10: Divide the sum by the size to calculate the average.

Step 11: Display the array, sum, and average of the numbers.
CODING:

size = int(input("Enter the size of thearray:"))

numbers = []

for i in range(size):

num = float(input("Enter a number: "))

[Link](num)

sum = 0

for num in numbers:

sum += num

average = sum / size

print("Array:", numbers)

print("Sum:", sum)

print("Average:", average)
OUTPUT:

Enter the size of the array: 4

Enter a number: 5

Enter a number: 2

Enter a number: 8

Enter a number: 3

Array: [5.0, 2.0, 8.0, 3.0]

Sum: 18.0

Average: 4.5

RESULT:
Thus the python program for using arrays was written executed and the output was verified.
[Link]. : 9 PROGRAM USING STRINGS Date:

AIM:

The aim of the program is to demonstrate various operations and manipulations on strings in
Python.

ALGORITHM:

Step 1: Prompt the user to enter a sentence.

Step 2: Read the input value and store it in a variable sentence.

Step 3: Calculate the length of the sentence using the len() function and store it in a variable

length.

Step 4: Split the sentence into words using the split() method and store the resulting list of words

in a variable words.

Step 5: Count the number of words in the sentence by calculating the length of the words list.

Step 6: Replace a specific word in the sentence with a new word.

Step 7: Prompt the user to enter the word to be replaced and the new word.

Step 8: Use the replace() method to replace the word in the sentence and store the modified

sentence in a variable modified_sentence.

Step 9: Display the length of the sentence, the number of words, and the modified sentence.
CODING:

sentence = input("Enter a sentence: ")

length = len(sentence)

words = [Link]()

word_count = len(words)

word_to_replace = input("Enter the word to replace: ")

new_word = input("Enter the new word: ")

modified_sentence = [Link](word_to_replace, new_word)

print("Length of the sentence:", length)

print("Number of words:", word_count)

print("Modified sentence:", modified_sentence)

OUTPUT:

Enter a sentence: Hello, how are you?

Enter the word to replace: how

Enter the new word: is

Length of the sentence: 19

Number of words: 4

Modified sentence: Hello, is are you?

RESULT:
Thus the python program for using Strings was written executed and the output was verified.
[Link]. : 10 PROGRAM USING MODULES Date:

AIM:

The aim of the program is to demonstrate the usage of modules in Python by importing and

utilizing functions from a separate module.

ALGORITHM:

Step 1: Import the required module that contains the desired functions.

Step 2: Prompt the user to enter two numbers.

Step 3: Read the input values and store them in variables num1 and num2.

Step 4: Call the imported function(s) from the module to perform desired operations on the input numbers.

Step 5: Display the output/result of the function(s).


CODING:

import math

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

sqrt = [Link](num1)

power = [Link](num1, num2)

print("Square root of", num1, "is", sqrt)

print(num1, "raised to the power of", num2, "is", power)

OUTPUT:

Enter the first number: 9

Enter the second number: 2

Square root of 9.0 is 3.0

9.0 raised to the power of 2.0 is 81.0

RESULT:
Thus the python program for using Modules was written executed and the output was verified.
[Link]. : 11 ROGRAM USING LISTS Date:

AIM:

The aim of the program is to demonstrate the usage of lists in Python by performing
various operations on a list of numbers.

ALGORITHM:

Step 1: Create an empty list to store numbers.

Step 2: Prompt the user to enter the size of the list.

Step 3: Read the input value and store it in a variable size.

Step 4: Use a loop to iterate size number of times.

Step 5: Inside the loop, prompt the user to enter a number and append it to the list.

Step 6: Calculate the sum and average of the numbers in the list.

Step 7: Initialize variables sum and average with the value 0.

Step 8: Use a loop to iterate through each element of the list.

Step 9: Add each element to the sum variable.

Step 10: Divide the sum by the size to calculate the average.

Step 11: Find the maximum and minimum values in the list using the max() and min() functions.

Step 12: Display the list, sum, average, maximum, and minimum values.
CODING:

size = int(input("Enter the size of the list: "))

numbers = []

for i in range(size):

num = float(input("Enter a number: "))

[Link](num)

sum = sum(numbers)

average = sum / size

maximum = max(numbers)

minimum = min(numbers)

print("List:", numbers)

print("Sum:", sum)

print("Average:", average)

print("Maximum:", maximum)

print("Minimum:", minimum)
OUTPUT:

Enter the size of the list: 5

Enter a number: 7

Enter a number: 4

Enter a number: 9

Enter a number: 2

Enter a number: 5

List: [7.0, 4.0, 9.0, 2.0, 5.0]

Sum: 27.0

Average: 5.4

Maximum: 9.0

Minimum: 2.0

RESULT:
Thus the python program for using Lists was written executed and the output was verified.
[Link]. : 12 PROGRAM USING TUPLES Date:

AIM:

The aim of the program is to demonstrate the usage of tuples in Python by performing
operations and accessing elements of a tuple.

ALGORITHM:

Step 1: Create a tuple to store a collection of elements.

Step 2: Prompt the user to enter values for the tuple.

Step 3: Read the input values and store them in variables.

Step 4: Perform operations on the tuple:

Step 5: Calculate the length of the tuple using the len() function.

Step 6: Access individual elements of the tuple using indexing.

Step 7: Slice the tuple to extract a subset of elements.

Step 8: Concatenate two tuples using the + operator.

Step 9: Display the length of the tuple, individual elements, sliced elements, and the

concatenated tuple.
CODING:

value1 = input("Enter the first value: ")

value2 = input("Enter the second value: ")

value3 = input("Enter the third value: ")

my_tuple = (value1, value2, value3)

length = len(my_tuple)

element1 = my_tuple[0]

sliced_tuple = my_tuple[1:3]

concatenated_tuple = my_tuple + ('extra',)

print("Length of the tuple:", length)

print("First element:", element1)

print("Sliced tuple:", sliced_tuple)

print("Concatenated tuple:", concatenated_tuple)

OUTPUT:

Enter the first value: Apple

Enter the second value: Banana

Enter the third value: Orange

Length of the tuple: 3

First element: Apple

Sliced tuple: ('Banana', 'Orange')

Concatenated tuple: ('Apple', 'Banana', 'Orange', 'extra')

RESULT:
Thus the python program for using Tuples was written executed and the output was verified.
[Link]. : 13 PROGRAM USING DICTIONARIES Date:

AIM:

The aim of the program is to demonstrate a simple usage of dictionaries in Python by storing and

accessing information about a person.

ALGORITHM:

Step 1: Create an empty dictionary to store information.

Step 2: Prompt the user to enter the name, age, and city of a person.

Step 3: Read the input values and store them in variables.

Step 4: Add the information to the dictionary using appropriate keys.

Step 5: Access the information from the dictionary using the keys.

Step 6: Display the stored information.

CODING:

person = {}

person['name'] = input("Enter the name: ")

person['age'] = input("Enter the age: ")

person['city'] = input("Enter the city: ")

print("Name:", person['name'])

print("Age:", person['age'])

print("City:", person['city'])
OUTPUT:

Enter the name: John

Enter the age: 25

Enter the city:

London Name: John

Age: 25

City: London

RESULT:
Thus the python program for using dictionaries was written executed and the output was verified.
[Link]. : 14 PROGRAM FOR FILE HANDLING Date:

AIM:

The aim of the program is to demonstrate file handling in Python by reading and writing
data to a file.

ALGORITHM:

Step 1: Prompt the user to enter a file name.

Step 2: Open the file in write mode and create a file object.

Step 3: Prompt the user to enter data to be written to the file.

Step 4: Write the data to the file using the file object.

Step 5: Close the file.

Step 6: Open the file in read mode and create a new file object.

Step 7: Read the contents of the file using the file object.

Step 8: Display the contents of the file.

Step 9: Close the file.


CODING:

filename = input("Enter the file name: ")

file = open(filename, 'w')

data = input("Enter data to be written to the file: ")

[Link](data)

[Link]()

file = open(filename, 'r')

contents = [Link]()

[Link]()

print("Contents of the file:")

print(contents)

OUTPUT:

Enter the file name: my_file.txt

Enter data to be written to the file: Hello, this is a file handling program.

Contents of the file:

Hello, this is a file handling program.

RESULT:
Thus the python program for using File Handling was written executed and the output was verified.

You might also like