DEPARTMENT OF SCIENCE AND HUMANITIES
ACADEMIC YEAR: 2024-2025
24ESC111- PROBLEM SOLVING AND PYTHON
PROGRAMMING LABORATORY
NAME : __________________________________
ROLL NO : __________________________________
BRANCH : __________________________________
YEAR/SEM : __________________________________
Certified that this is the bonafide record of work done by
Mr./Ms......................................................................................in the 24ESC111-
PROBLEM SOLVING AND PYTHON PROGRAMMING
LABORATORY at this institution, as prescribed by Sree Sakthi Engineering
College (Autonomous) for the SECOND Semester, Department of Science and
Humanities during the year 2024-2025.
Staff - In charge Head of the Department
Submitted for the End Semester Practical Examination held on ......................at
Sree Sakthi Engineering College, Coimbatore – 641 104.
Internal Examiner External Examiner
LIST OF EXPERIMENTS
NAME OF THE PAGE FACULTY
S.NO DATE MARKS
EXPERIMENT NO SIGN
Identification and solving of simple real
life or scientific or technical problems, and
developing flow charts for the same.
1 (Electricity Billing, Retail shop billing,
Sin series, weight of a motorbike, Weight
of a steel bar, compute Electrical Current
in Three Phase AC Circuit, etc.)
Python programming using simple
statements and expressions (exchange the
2 values of two variables, circulate the
values of n variables, distance between two
points)
Scientific problems using Conditionals and
3 Iterative loops. (Number series, Number
Patterns, pyramid pattern)
Implementing real-time/technical
applications using Lists, Tuples. (Items
4 present in a library/Components of a car/
Materials required for construction of a
building –operations of list & tuples)
Implementing real-time/technical
applications using Sets, Dictionaries.
5 (Language, components of an automobile,
Elements of a civil structure, etc.
operations of Sets & Dictionaries)
Implementing programs using Functions.
6 (Factorial, largest number in a list, area of
shape)
Implementing programs using Strings.
7 (reverse, palindrome, character count,
replacing characters)
1
Ex. No : 1(a)
Date : ELECTRICITY BILLING
AIM:
To Draw a flowchart for Electricity Billing.
ALGORITHM:
Step1: Start.
Step2: Read the previous unit and current unit.
Step 3: Calculate the used units by subtracting the current unit and
Previous units.
Step4: Calculate the Electricity bill from the used units.
Step 5: Print the amount of electricity bill.
Step6: Stop.
PSEUDOCODE:
READ Previous unit, Current Unit
CALCULATE Used Unit = Current Unit – Previous Unit
ElectricityBill=Used Unit x 2
PRINT ElectricityBill
2
FLOWCHART:
RESULT:
Thus the electricity billing calculation in real time were identified and
solved.
3
Ex. No : 1(b)
Date : RETAIL SHOP BILLING
AIM:
To develop a flowchart for the retail shop billing.
ALGORITHM:
Step1: Start.
Step2: Read the barcode of the product.
Step3: Display the product name and the amount.
Step 4: Check if more products is available, if available go to Step 2,
otherwise go to Step 5.
Step5: Calculate the total cost of the products.
Step6: Print total cost.
Step7: Stop.
PSEUDOCODE:
IF more products available THEN
READ bar code
DISPLAY Product name, amount
ELSE
CALCULATE TotalCost
PRINT Total Cost
ENDIF
4
FLOWCHART:
RESULT:
Thus the Retail shop billing calculation in real time were identified and
solved.
5
Ex. No : 1(c)
Date : SIN SERIES
AIM:
To develop a flowchart for the Sine Series.
ALGORITHM:
Step 1: Start
Step 2: Read x and n
Step 3: Print x and n
Step 4: Convert x to radians: x = x * 3.1412 / 180
Step 5: Initialize t = x, sum = x
Step 6: For i = 1 to n:
a. T = (t * -1 * x * x) / (2*i * (2*i + 1))
b. Sum = sum + t
Step 7: Print sum
Step 8: Stop
PSEUDOCODE:
READ x, n
X = x * 3.1412 / 180
T = sum = x
FOR i = 1 to n
t = (t * -1 * x * x) / (2*i * (2*i + 1))
sum = sum + t
END
PRINT sum
FLOWCHART:
RESULT:
Thus the sin series calculation in real time were identified and solved.
7
Ex. No : 1(d)
Date : WEIGHT OF A MOTOR BIKE
AIM:
To develop a flowchart for finding the weight of a motor bike.
ALGORITHM:
Step 1: Start
Step 2: Read bike size (cc)
Step 3:
• If cc ≤ 300 → Print “Average weight: 350 pounds”
• Else if cc ≤ 500 → Print “Average weight: 410 pounds”
• Else if cc ≤ 900 → Print “Average weight: 430 pounds”
• Else if cc = 1100 → Print “Average weight: 500 pounds”
• Else → Print “Average weight: 600 pounds”
Step 4: Stop
PSEUDOCODE:
READ size in cc
IF size <= 300 THEN
PRINT “Average weight = 350 pounds”
ELSE IF size <= 500 THEN
PRINT “Average weight = 410 pounds”
ELSE IF size <= 900 THEN
PRINT “Average weight = 430 pounds”
ELSE IF size = 1100 THEN
PRINT “Average weight = 500 pounds”
ELSE
PRINT “Average weight = 600 pounds”
ENDIF
8
FLOWCHART:
RESULT:
Thus, the flowchart for finding the weight of the motor bike is developed.
9
Ex. No : 1(e)
Date : WEIGHT OF A STEEL BAR
AIM:
To develop a flowchart for finding weight of a steel bar.
ALGORITHM:
Step 1: Start
Step 2: Read diameter (mm) and length
Step 3:
• If length is in meters → weight = (d × d × length) / 162
• Else → weight = (d × d × length) / 533
Step 4: Print weight
Step 5: Stop
PSEUDOCODE:
READ diameter, length
IF length is in meter THEN
Weight = diameter * diameter * length / 162
ELSE
Weight = diameter * diameter * length / 533
ENDIF
PRINT Weight
10
FLOWCHART:
RESULT:
Thus, the flowchart for finding the weight of a steel bar is developed.
11
Ex. No : 1(f)
COMPUTE ELECTRICAL CURRENT IN THREE PHASE
Date :
AC CIRCUIT
AIM:
To develop a flowchart to compute electrical current in three phase AC
circuit.
ALGORITHM:
Step1: Start.
Step2: Get the value of voltage, resistance, current and power factor.
Step3: Compute the electric current by multiplying voltage, resistance,
current and power factor with 3.
Step 4: Print the calculated electric current.
Step5: Stop.
PSEUDOCODE:
READ voltage, resistance, current and power factor
COMPUTE Electric Current = 3 x voltage x resistance x current x power
factor
PRINT Electric Current
12
FLOWCHART:
RESULT:
Thus, the flowchart for computing the electric current in three phase AC
circuit is developed.
13
Ex. No : 2(a)
Date : EXCHANGE THE VALUES OF TWO VARIABLES
AIM:
To write a python program for exchanging the values of two variables by
using simple statement.
ALGORITHM:
Step 1: start.
Step 2: Get the input values as a, b.
Step 3: swapping the values as a,b=b,a
Step 4: print the swapped values
Step 5: stop.
PROGRAM
a = int(input(“Enter the first number (a): “))
b = int(input(“Enter the second number (b): “))
print(“Before swapping: a =”, a, “b =”, b)
a, b = b, a
print(“After swapping: a =”, a, “b =”, b)
OUTPUT
RESULT:
Thus the program for exchanging the values of two variables has been
implemented and the output verified successfully.
14
Ex. No : 2(b)
Date : CIRCULATE THE VALUES OF N VARIABLES
AIM:
To write a python program for circulate the values of ‘n’ variables.
ALGORITHM:
Step 1: Start
Step 2: Input n and list values
Step 3: Save original_values = values
Step 4: Print “Step 0” and original list
Step 5: Set step = 1
Step 6: Rotate list, print with step number
Step 7: Repeat Step 6 until list = original_values
Step 8: Stop
PROGRAM
n = int(input(“Enter the number of elements: “))
values = input(“Enter the values separated by spaces: “).split()
original_values = values[:]
print(“Step 0:”, values)
step = 1
while True:
values = values[1:] + values[:1]
print(“Step”, step, “:”, values)
if values == original_values:
break
step += 1
15
OUTPUT
RESULT:
Thus the program for Circulate the values of n variables has been
implemented and the output verified successfully.
16
Ex. No : 2(c)
Date : DISTANCE BETWEEN TWO POINTS
AIM:
To write a python program for distance between two points by using simple
statement.
ALGORITHM:
Step 1: start.
Step 2: import the math function.
Step 3: Get input value of (x,y) coordinates.
Step 4: Use math.sqrt function to calculate the distance between two points.
Step 5: print the distance.
Step 5: stop.
PROGRAM
Import math
x1 = float(input(“Enter x1: “))
y1 = float(input(“Enter y1: “))
x2 = float(input(“Enter x2: “))
y2 = float(input(“Enter y2: “))
distance = math.sqrt((x2 – x1) ** 2 + (y2 – y1) ** 2)
print(“Distance between points:”, distance)
17
OUTPUT:
RESULT:
Thus the program for distance between two points has been implemented
and the output verified successfully.
18
Ex. No : 3(a)
Date : NUMBER SERIES
AIM:
To write a python program for number series by using iterative loops.
ALGORITHM:
Step 1: Start.
Step 2: Get the first term (a).
Step 3: Get the common difference (d).
Step 4: Get the number of terms (n).
Step 5: Use a loop to generate the series:
For each i from 0 to n-1:
● Compute the term: term = a + i * d.
● Print the term.
Step 6: Stop.
PROGRAM
a = int(input(“Enter the first term (a): “))
d = int(input(“Enter the common difference (d): “))
n = int(input(“Enter the number of terms (n): “))
print(“Arithmetic Number Series:”)
for i in range(n):
term = a + i * d
print(term, end=” “)
19
OUTPUT:
RESULT:
Thus the program for number series has been implemented and the output
verified successfully.
20
Ex. No : 3(b)
Date : NUMBER PATTERN
AIM:
To write a python program for number pattern by using iterative loops.
ALGORITHM:
Step 1: Start
Step 2: Input number of rows n
Step 3: Set num = 1
Step 4: Loop i = 1 to n
Step 4.1: Loop j = 1 to i: print num, increment num
Step 4.2: Print new line
Step 5: Stop
PROGRAM
n = int(input(“Enter the number of rows: “))
num = 1
for i in range(1, n + 1):
for j in range(i):
print(num, end=” “)
num += 1
print()
21
OUTPUT:
RESULT:
Thus the program for number pattern has been implemented and the
output verified successfully.
22
Ex. No : 3(c)
Date : PYRAMID PATTERN
AIM:
To write a python program for pyramid pattern by using iterative loops.
ALGORITHM:
Step 1: Start
Step 2: Input number of rows n
Step 3: Set i = 1
Step 4: While i ≤ n:
4.1: Print (n – i) spaces
4.2: Print i stars (*)
4.3: Increment i
Step 5: Stop
PROGRAM:
n = int(input(“Enter the number of rows: “))
i= 1
while i <= n:
print(“ “ * (n – i) + “* “ * i)
i += 1
23
OUTPUT:
RESULT:
Thus the program for pyramid pattern has been implemented and the output
verified successfully.
24
Ex. No : 4(a)
Date : ITEMS PRESENT IN A LIBRARY
AIM:
To write a python program for items present in a library using tuple operations.
ALGORITHM:
Step 1: start
Step 2: initialize library details as tuple values.
Step 3: perform tuple operations like index, length, concatenation, repetition,
membership.
Step 4: slice the tuple value.
Step 5: print all the tuple operation results.
Step 6: stop.
PROGRAM
library_items = (“Harry Potter”, “The Lord of the Rings”, “Sherlock Holmes”,
“The Alchemist”)
print(“Books in the library:”, library_items)
library_items = library_items + (“Pride and Prejudice”,)
print(“After adding ‘Pride and Prejudice’:”, library_items)
library_items = library_items[:2] + library_items[3:]
print(“After removing ‘Sherlock Holmes’:”, library_items)
25
OUTPUT
RESULT:
Thus the program for items present in a library using tuple operations has
been implemented and the output verified successfully.
26
Ex. No : 4(b)
Date : CONSTRUCTION OF A BUILDING
AIM:
To write a python program for materials required for construction of a
building using tuple operations.
ALGORITHM:
Step 1: start
Step 2: initialize materials required for construction of a building as tuple
values.
Step 3: perform tuple operations like index, concatenation, count, membership.
Step 4: slice the tuple value.
Step 5: print all the tuple operation results.
Step 6: stop.
PROGRAM
materials = (“Cement”, “Bricks”, “Sand”, “Steel”, “Wood”)
materials = materials + (“Glass”,)
print(“Bricks appears:”, materials.count(“Bricks”))
print(“Index of Steel:”, materials.index(“Steel”))
if “Cement” in materials:
print(“’Cement’ is available in the list.”)
print(“List of materials:”)
for material in materials:
print(“-“, material)
27
OUTPUT
RESULT:
Thus the program for materials required for construction of a building using
tuple operations has been implemented and the output verified successfully.
28
Ex. No : 4(c)
Date : COMPONENTS OF CAR
AIM:
To write a python program for components of a car using list operations.
ALGORITHM:
Step 1: start
Step 2: initialize components of a cars list values.
Step 3: perform list operations like length, concatenation, repetition,
membership.
Step 4: slice the list value.
Step 5: print all the list operation results.
Step 6: stop.
PROGRAM
car_components = [“Engine”, “Transmission”, “Brakes”, “Steering”, “Battery”]
print(“Initial:”, car_components)
car_components.insert(2, “Wheels”)
print(“After inserting ‘Wheels’:”, car_components)
car_components.remove(“Battery”)
print(“After removing ‘Battery’:”, car_components)
car_components.sort()
print(“Sorted:”, car_components)
car_components.reverse()
print(“Reversed:”, car_components)
print(“Count of ‘Engine’:”, car_components.count(“Engine”))
29
OUTPUT
RESULT:
Thus the program for components of a car using list operations has been
implemented and the output verified successfully.
30
Ex. No : 5(a)
Date : LANGUAGE DETAILS
AIM:
To write a python program for programming language details using set
operations.
ALGORITHM:
Step 1: start
Step 2: initialize programming language details of set values.
Step 3: perform set operations like union, intersection and set difference.
Step 4: print all the set operation results.
Step 5: stop.
PROGRAM
web = {‘HTML’, ‘CSS’, ‘JavaScript’, ‘Python’, ‘PHP’}
app = {‘Java’, ‘Kotlin’, ‘Swift’, ‘Python’, ‘Dart’}
game = {‘C++’, ‘C#’, ‘Python’, ‘Lua’, ‘Java’}
print(“All Languages:”, web | app | game)
print(“Common to All Domains:”, web & app & game)
print(“Web & App:”, web & app)
print(“Web not in Game:”, web – game)
print(“Unique to Web:”, web – (app | game))
print(“Unique to App:”, app – (web | game))
print(“Unique to Game:”, game – (web | app))
31
OUTPUT:
RESULT:
Thus the program for programming languages using set operations has
been implemented and the output verified successfully.
32
Ex. No : 5(b)
Date : COMPONENTS OF AN AUTOMOBILE
AIM:
To write a python program for implementing components of an
automobile using dictionaries.
ALGORITHM:
Step 1: start
Step 2: initialize components of an automobile using Dictionaries.
Step 3: perform dictionaries operations like add items, accessing the items and
membership operator .
Step 4: print all the dictionary operation results.
Step 5: stop
PROGRAM
print(“Automobile Components using Dictionary”)
automobile = {“engine”: “V8”, “transmission”: “Automatic”, “wheels”: 4,
“fuel_type”: “Petrol”}
print(“Engine Type:”, automobile[“engine”])
print(“Number of Wheels:”, automobile[“wheels”])
if “transmission” in automobile:
print(“Transmission is present in the components.”)
automobile[“color”] = “Red”
automobile[“airbags”] = 6
print(“Updated Automobile Dictionary:”, automobile)
33
OUTPUT
RESULT:
Thus the program for components of an automobile using dictionary
operations has been implemented and the output verified successfully.
34
Ex. No : 6(a)
Date : FACTORIAL
AIM:
To write a python program for factorial using user defined functions.
ALGORITHM:
Step 1: start
Step 2: initialize num variable to get the input.
Step 3: user defined function is defined for factorial of the given value .
Step 4: check the values using conditionals.
Step 5: calculate the factorial by using function recursion.
Step 6: print the factorial result.
Step 5: stop the process.
PROGRAM:
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n-1)
num = int(input(“Enter the number:”))
result = factorial(num)
print(“Factorial of”,num,”is:”,result)
OUTPUT
RESULT:
Thus the program for factorial of given number using user defined
functions has been implemented and the output verified successfully.
35
Ex. No : 6(b)
Date : LARGEST NUMBER IN THE LIST
AIM:
To write a python program for largest number in the list using user defined
functions.
ALGORITHM:
Step 1: Start
Step 2: Input number of elements (size)
Step 3: Read size numbers into list nums
Step 4: Set largest = nums[0]
Step 5: For each number in nums:
• if number > largest, update largest
Step 6: Print largest
Step 7: Stop
PROGRAM
def find_largest(numbers):
largest = numbers[0]
for num in numbers:
if num > largest:
largest = num
return largest
size = int(input(“Enter the number of elements: “))
nums = []
for i in range(size):
val = int(input(”Enter number”,(i + 1),”:”))
nums.append(val)
largest = find_largest(nums)
print(“The largest number in the list is:”, largest)
36
OUTPUT:
RESULT:
Thus the program for largest number of the given list using user defined
functions has been implemented and the output verified successfully.
37
Ex. No : 6(c)
Date : AREA OF RECTANGLE, SQUARE, TRIANGLE, CIRCLE
AIM:
To write a python program for find the area of different shapes.
ALGORITHM:
Step 1: start
Step 2: get the shape from the user to calculate area.
Step 3: call the function for the user defined shape.
Step 4: calculate the area of different shapes like rectangle, square, triangle,
circle.
Step 5: print the area of shape for user specified.
Step 6: stop.
PROGRAM
import math
def area(shape):
if shape == ‘circle’:
r = float(input(“Radius: “))
return math.pi * r ** 2
elif shape == ‘rectangle’:
l = float(input(“Length: “))
w = float(input(“Width: “))
return l * w
elif shape == ‘triangle’:
b = float(input(“Base: “))
h = float(input(“Height: “))
return 0.5 * b * h
38
elif shape == ‘square’:
s = float(input(“Side: “))
return s ** 2
else:
return “Invalid shape”
shape = input(“Enter shape (circle/rectangle/triangle/square): “).lower()
print(“Area:”, area(shape))
OUTPUT
RESULT:
Thus the program for area of different shapes using user defined functions
has been implemented and the output verified successfully.
39
Ex. No : 7 STRING
Date : METHODS (REVERSE, PALINDROME, CHARACTER
COUNT, REPLACING CHARACTER)
AIM:
To write a python program for string methods for reverse, palindrome,
character count, replacing character and check whether the given string is
palindrome or not.
ALGORITHM:
Step 1: start
Step 2: get the string from the user to manipulate string methods.
Step 3: use the string method[::-1],for displaying reverse of the string.
Step 4: check whether the string is palindrome or not using palindrome
function.
Step 5: use len(str),for finding character count
Step 6: use replace(),for finding replacing character
Step 7: stop.
PROGRAM
text = input(“Enter a string: “)
reversed_text = text[::-1]
print(“Reversed String:”, reversed_text)
if text == reversed_text:
print(“The string is a palindrome.”)
else:
print(“The string is not a palindrome.”)
print(“Character Count:”, len(text))
old_char = input(“Enter character to replace: “)
new_char = input(“Enter new character: “)
replaced_text = text.replace(old_char, new_char)
40
print(“String after replacement:”, replaced_text)
OUTPUT:
RESULT:
Thus the program for string methods like reverse, palindrome, character
count, replacing character and check whether the given string is palindrome or
not has been implemented and the output verified successfully.
41
42