Final Record I Guess
Final Record I Guess
STMARY'S NAGAR,THIRUNINRAVUR-602024
EMAIL: [email protected]
WEBSITE: WWW.SAKTHIEC.EDU.IN
I YEAR/I SEMESTER
NAME :
REGISTER NO :
DEPARTMENT :
ANNA UNIVERSITY
JAYA SAKTHI ENGINEERING COLLEGE
THIRUNINRAVUR - 602024
EMAIL : [email protected]
WEBSITE : WWW.SAKTHIEC.EDU.IN
BONAFIDE CERTIFICATE
NAME : REGISTER NO :
BRANCH : YEAR/SEM:
This is certified to be a Bonafide record of work done by the student in the GE3171- Problem
Solving And Python Programming Laboratory of the Jaya Sakthi Engineering College during
.
1 Identification and solving of simple real life or scientific or technical problems, and developing
1a Electricity Billing
1c Sin series
1d Weight of a motorbike
3a Number series
3b Number Patterns
AIM:
To write a Python Program for implementing electricity billing
ALGORITHM:
1. Start the program.
2. Get the total units of current consumed by the customer using the
variable unit.
3. If the unit consumed less or equal to 100 units, Total amount is 0
4. If the unit consumed between 101 to 200 units, Total amount =
((101*1.5)+(unit-100)*2)
5. If the unit consumed between 201 to 500 units, Total amount =
((101*1.5)+(200-100)*2+(unit-200)*3)
6. If the unit consumed 300 to 350, Total amount = ((101*1.5)+(200-
100)*2+(300-200)*4.6+(unit-350)*5)
7. If the unit consumed above 350, fixed charge – 1500
8. Stop the program
FLOWCHART:
PROGRAM:
# Electricity billing
# Input the number of units consumed
unit = int(input("Enter the number of units: "))
# Rate structure
rates = [
[0], # Placeholder for 0 units
[0, 1.5], # Rates for 1-100 units
[0, 2.5, 3.5], # Rates for 101-200 and 201-500 units
[0, 3.5, 4.6, 6.6] # Rates for 501+ units
]
# Initialize bill
bill = 0
# Calculate the bill based on the number of units consumed
if unit >= 0 and unit <= 100:
bill = unit * rates[1][1]
elif unit <= 200:
bill = (100 * rates[1][1]) + (unit - 100) * rates[2][1]
elif unit <= 500:
bill = (100 * rates[1][1]) + (100 * rates[2][1]) + (unit - 200) * rates[2][2]
else:
bill = (100 * rates[1][1]) + (100 * rates[2][1]) + (300 * rates[2][2]) + (unit -
500) * rates[3][3]
# Print the results
print("Units consumed:", unit)
print("Bill: Rs", bill)
OUTPUT:
RESULT:
Thus, a Python Program for calculating electricity bill was executed and
the output was obtained.
1b) Retail Shop Billing
AIM:
To write a Python Program for implementing retail shop billing
ALGORITHM:
1. Start the program.
2. Assign tax =0.5
3. Assign rate for Shirt, Saree, T-shirt, Trackpant
4. Get the quantity of items from the user
5. Calculate total cost by multiplying rate and quantity of the items
6. Add tax value with the total cost and display the bill amount
7. Stop the program
FLOWCHART:
PROGRAM:
# Retail Shop Billing Tax
tax = 0.5
Rate = {"Shirt": 250, "Saree": 650, "T-Shirt": 150, "Trackpant": 150}
print("Retail Bill Calculator\n")
# Input quantities
Shirt = int(input("Shirt: "))
Saree = int(input("Saree: "))
TShirt = int(input("T-Shirt: "))
Trackpant = int(input("Trackpant: "))
# Calculate cost
Cost = (Shirt * Rate["Shirt"] +
Saree * Rate["Saree"] +
TShirt * Rate["T-Shirt"] +
Trackpant * Rate["Trackpant"])
# Calculate total bill including tax
Bill = Cost + Cost * tax
# Print the total bill
print("Please pay Rs. %.2f" % Bill)
OUTPUT:
Shirt: 1
Saree: 1
T-Shirt: 2
Trackpant: 3
Please pay Rs. 2475.00
RESULT:
Thus, a Python Program for calculating retail bill was executed and the
output was obtained.
1c) Weight of a Steel Bar
AIM:
To write a Python Program to find unit weight of steel bars.
ALGORITHM:
1. Start the program.
2. Read D, Diameter of the steel bars.
3. Calculate W = D*D/162.
4. Print W, unit weight of the steel bars in kg/m
5. Stop.
FLOWCHART:
PROGRAM:
OUTPUT:
RESULT:
Thus, a Python Program for calculating unit weight of steel bars was
executed and the output was obtained.
1d) Weight of a Motorbike
AIM:
To write a Python Program to find weight of motorbike.
ALGORITHM:
FLOWCHART:
PROGRAM:
# WEIGHT OF MOTORBIKE
OUTPUT:
RESULT:
AIM:
To write a Python Program to compute Electrical Current in Three Phase AC
Circuit.
ALGORITHM:
FLOWCHART:
START
STOP
PROGRAM:
# Input values
# Calculate current
I = P / (V * PF)
OUTPUT:
RESULT:
AIM:
ALGORITHM:
1. Start
2. Initialize double sum=0,x,i,j,y,z=1,a,f=1,k=1;
3. Enter x.
4. read x.
5. repeat steps 6 to 11 for(i=1 to i<=x)
6. set j=z=1
7. repeat steps 8 while(j<=i)
8. set z=z*i;
9. j=j+1;
10. repeat steps 10 while(k<=i).
FLOWCHART:
PROGRAM:
import math
def sine_series(x, n):
# Convert x from degrees to radians
x = math.radians(x)
# Initialize sine value
sine_value = 0
# Calculate sine series
for i in range(n):
# Calculate the term using the Taylor series formula
term = ((-1) ** i) * (x ** (2 * i + 1)) / math.factorial(2 * i + 1)
sine_value += term
return sine_value
# Input values
n = int(input("Enter the number of terms in the series: ")) # Number of terms
x = float(input("Enter the angle in degrees: ")) # Angle in degrees
# Calculate sine using the series
result = sine_series(x, n)
# Print the result
print("The sine of {} degrees using {} terms is {:.5f}".format(x, n, result))
OUTPUT:
RESULT:
Thus, a Python Program to compute sine series was executed and the
output was obtained.
PYTHON PROGRAMMING USING SIMPLE STATEMENTS AND
EXPRESSIONS
2 a) SWAPPING OF TWO NUMBERS USING TEMPORARY VARIABLE
AIM:
FLOWCHART:
START
Read a and b
c=a
a=b
b=c
Print a and b
STOP
PROGRAM:
# Input values
print("Before Swapping")
Temp = X
X=Y
Y = Temp
print("After Swapping")
OUTPUT:
AIM:
To write a Python Program to swap two numbers without using a temporary
variable.
ALGORITHM:
FLOWCHART:
PROGRAM:
# Input values
print("Before Swapping")
X=X+Y
Y=X-Y
X=X-Y
print("After Swapping")
OUTPUT:
AIM:
To write a Python Program to swap two numbers using Tuple Assignment.
ALGORITHM:
PROGRAM:
# SWAPPING OF TWO NUMBERS USING TUPLE ASSIGNMENT
X=int(input("Enter the value of X:") )
Y=int(input("Enter the value of Y:") )
X,Y=Y,X
OUTPUT:
Enter the value of X:1
Enter the value of Y:2
Before Swapping
X= 1 Y= 2
After Swapping
X= 2 Y= 1
RESULT:
Thus, a Python Program to swap two numbers using tuple assignment
was executed and the output was obtained.
2 d) DISTANCE BETWEN TWO POINTS
AIM:
To write a Python Program to calculate distance between two points.
ALGORITHM:
FLOWCHART:
PROGRAM:
print("Distance is {:.4f}".format(distance))
OUTPUT:
Enter the value of X1:2
Enter the value of Y1:3
Enter the value of X2:4
Enter the value of Y2:5
Distance is 2.8284
RESULT:
AIM:
To write a Python Program to calculate distance between two points using
list.
ALGORITHM:
PROGRAM:
print("Distance is {:.4f}".format(distance))
OUTPUT:
Distance is 2.8284
RESULT:
Thus, a Python Program to calculate the distance between two points
using list was executed and the output was obtained.
2 f) CIRCULATE THE VALUES OF N VARIABLES
AIM:
To write a Python Program to circulate the values of N variables.
ALGORITHM:
FLOWCHART:
PROGRAM:
B = A[i:] + A[:i]
print("Circulation", i, "=", B)
# Main code
OUTPUT:
Enter n: 13
RESULT:
Thus, a Python Program to circulate the number was executed and the
output was obtained.
3. SCIENTIFIC PROBLEMS USING CONDITIONALS AND
ITERATIVE LOOPS
ALGORITHM:
FLOWCHART:
PROGRAM:
# Input a number
while i <= N:
i += 1 # Increment i
OUTPUT:
Enter a number : 10
Sum = 385
RESULT:
Thus, a Python Program to calculate number series was executed and
the output was obtained.
3b) NUMBER PATTERNS
AIM:
To write a Python Program to print odd number pattern of the given number
of terms.
ALGORITHM:
FLOWCHART:
PROGRAM:
print("Number Triangle:")
OUTPUT:
RESULT:
Thus, a Python Program to print number pattern was executed and the
output was obtained.
3C) PYRAMID PATTERN
AIM:
ALGORITHM:
def full_pyramid(n):
print("*", end="")
full_pyramid(num_rows)
OUTPUT:
*
***
*****
*******
*********
RESULT:
Thus, a Python Program to print pyramid pattern was executed and the
output was obtained.
4. REAL TIME/ TECHNICAL APPLICATIONS USING LISTS,
TUPLES
.
AIM:
ALGORITHM:
1. Start
2. Perform update operation (Insert , Delete, modify, slice) on List object
3. Display the outputs
4. Stop.
PROGRAM:
carparts.append('Headlights')
carparts.insert(2, 'Radiator')
carparts.remove('Headlights')
carparts.pop(2)
print("After popping the part at index 2:", carparts)
carparts[2] = 'Tyre'
carparts.sort()
carparts.reverse()
New = carparts[:]
x = slice(2)
test_list1 = [1, 4, 5, 6, 5]
test_list2 = [3, 5, 7, 2, 5]
for i in test_list2:
test_list1.append(i)
OUTPUT:
RESULT:
Thus, a Python Program to perform List operation was executed and the
output was verified.
4b) Building Materials
.
AIM:
ALGORITHM:
1. Start
2. Perform update operation (Insert , Delete, modify, slice) on List object
3. Display the outputs
4. Stop.
PROGRAM:
OUTPUT:
RESULT:
Thus, a Python Program to perform List operation was executed and the
output was verified.
5. REAL TIME/ TECHNICAL APPLICATIONS USING SETS,
DICTIONARIES
ALGORITHM:
1. Start
2. Perform update operation (Insert, Delete, modify) on Dictionary
operations
3. Display the outputs
4. Stop.
PROGRAM:
# Dictionary of building materials
Building_materials = {
1: "Cement",
2: "Bricks",
3: "Sand",
4: "Steel rod",
5: "Paint"
}
OUTPUT:
RESULT:
AIM:
ALGORITHM:
1. Start
2. Perform update operation (Insert, Delete, modify) on Dictionary
operations.
3. Display the outputs
4. Stop.
PROGRAM:
RESULT:
Thus, a Python Program to perform Dictionary operation was executed
and the output was verified.
6. IMPLEMENTING PROGRAMS USING FUNCTION
6 a) FACTORIAL OF A NUMBER
AIM:
To write a Python Program to find the factorial of the given number using
functions.
ALGORITHM:
1: Start
2: Input N
3: Initialize F=1
4: Repeat until I= 1 to N
5: Calculate F=F*I
6: print F
7: Stop
PROGRAM:
# FACTORIAL OF A NUMBER
def Fact(N):
F=1
if N == 0 or N == 1: # Handle the case for 0 as well
return 1
else:
return N * Fact(N - 1)
OUTPUT:
Enter a number:6
Factorial of 6 is 720
RESULT:
Thus, a Python Program to find the factorial of the given number using
functions was executed and the output was obtained.
6b) AREA OF SHAPE
AIM:
To write a Python Program to find the area of the shape using functions
ALGORITHM:
1: Start
2: Input shape of the area
3: call the function to calculate area of shape
4: print area
5: Stop
PROGRAM:
# AREA OF SHAPE
def calculate_area(name): if
name == "rectangle":
a = int(input("Enter rectangle length: "))
b = int(input("Enter rectangle breadth: ")) area =
a*b
print("The area of rectangle is:", area) elif
name == "square":
s = int(input("Enter length of side: ")) area = s
*s
print("The area of square is:", area) elif
name == "circle":
r = float(input("Enter radius: ")) pi =
3.14
area = pi * r * r
print("The area of circle is:", area) else:
print("Invalid shape!") # Handle invalid shape input
RESULT:
Thus, a Python Program to calculate area of shape was executed and
the output was obtained.
6c) FINDING LARGEST NUMBER IN A LIST
AIM:
ALGORITHM:
1: Start
2: Read number of elements from user
3: Read the elements of lists using for loop
4: Find the largest element from list using max() function
5: Print the result
6: Stop
PROGRAM:
# Main program
n = int(input("Enter no. of elements: ")) # Get the number of elements
numbers = [] # Initialize an empty list
Enter 3 elements
Enther a number:232
Enther a number:246
Enther a number:135
RESULT:
7 a) REVERSE OF A STRING
AIM:
To write a Python Program to reverse a string
ALGORITHM:
PROGRAM:
# Main program
# Get user input
input_str = input("Enter a string: ") # Prompt the user to enter a string
# Reverse the string
reversed_str = reverse_string(input_str)
# Print the reversed string
print("Original string is:", input_str)
print("Reversed string is:", reversed_str)
OUTPUT:
RESULT:
AIM:
To write a python Program to perform string operations for the following using
built-in functions: Palindrome.
ALGORITHM:
1. Start
2. Read the text.
3. Display the reverse of the text using Slicing operator.
4. Reversed text and Original text are same then print the text is Palindrome.
5. Stop.
PROGRAM:
OUTPUT:
RESULT:
AIM:
To write a python Program to perform string operations for the following using
built-in functions: Character count.
ALGORITHM:
1. Start
2. Read the text.
3. Read the character to be counted.
4. Using count method count the appearance of the character.
5. print the count.
6. Stop
PROGRAM:
OUTPUT:
RESULT:
AIM:
To write a python Program to perform string operations for the following using
built-in functions: Replace the characters.
ALGORITHM:
1. Start
2. Read the text.
3. Read the Text to be replaced and the Replace Text.
4. Using replace method replace the text.
5. print the Replace Text.
6. Stop
PROGRAM:
Replaced Text:
Internal test Internal score Class average
RESULT:
Thus, a Python Program to perform String operation was executed and the
output was verified.
8. IMPLEMENTING PROGRAMS USING WRITTEN MODULES
AND PYTHON STANDARD LIBRARIES
8 a) PANDAS
AIM:
PROGRAM:
import pandas as pd
# Print Series 1
print("Series 1:")
print(ds1)
# Print Series 2
print("Series 2:")
print(ds2)
# Compare the elements of the two Series
print("Compare the elements of the said Series:")
print("Equals:")
print(ds1 == ds2) # Check for equality
print("Greater Than:")
print(ds1 > ds2) # Check if elements in ds1 are greater than those in ds2
print("Less Than:")
print(ds1 < ds2) # Check if elements in ds1 are less than those in ds2
OUTPUT:
Series 1:
0 2
1 4
2 6
3 8
4 10
dtype: int64 Series 2:
0 1
1 3
2 5
3 7
4 10
dtype: int64
Compare the elements of the said Series: Equals:
0 False
1 False
2 False
3 False
1 True
2 True
3 True
4 False dtype:
bool Less Than:
0 False
1 False
2 False
3 False
4 False dtype:
bool
RESULT:
Thus, a Python Program to use pandas library was executed and the output
was verified.
8 b) Numpy
AIM:
PROGRAM:
import numpy as np
RESULT:
Thus, a Python Program to use numpy library was executed and the output
was verified.
8 c) MATPLOTLIB
AIM:
To write a python program to plot a graph using matplotlib library
ALGORITHM:
1. Start the program
2. Import matplotlib from python standard library
3. Declare two arrays to define coordinators for 2 points
4. Plot graph for those mentioned points using matplot library
5. Stop the Program.
PROGRAM:
import matplotlib.pyplot as
plt # Define the data points
x = [1,2,3,4,5]
y = [1,2,3,4,5]
# Create a scatter plot
plt.scatter(x, y, color='blue',
marker='o') # Add title and labels
plt.title("Scatter Plot of
Points") plt.xlabel("X-
axis") plt.ylabel("Y-axis")
# Show the
plot plt.grid()
plt.show()
OUTPUT:
RESULT:
Thus, a Python Program to use matplolib was executed and the output was
verified.
8 d) SCIPY
AIM:
To write a python program to return the specified unit in seconds using sciptlibrary
ALGORITHM:
1. Start the program
2. Import scipy from python standard library
3. Print specified units like minute, hour, day etc
4. Stop the Program.
PROGRAM:
OUTPUT:
Thus, a Python Program to use scipy library was executed and the output was verified.
9. IMPLEMENTING REAL TIME /TECHNICAL APPLICATIONS
USING FILE HANDLING
9 a) FILE COPY
AIM:
To write a Python Program to copy the content of one file into another using
File manipulation function and methods.
ALGORITHM:
1: Start
2: Open a file named source.txt in read mode
3: Open a file named dest.txt in write mode
4: Read the content of file source.txt line by line using
for loop
5: Write the content onto file dest.txt usint write()
function
6: Close the file
7: Open a file named dest.txt in read mode
8: Read the content of file dest. using read() function
and display the content
9: Stop
PROGRAM:
# FILE COPY
fp1=open("source.txt","w")
fp1.write("python python\n")
fp1.write("java python\n")
fp1.write("c java\n")
fp1=open("source.txt","r")
fp2=open("dest.txt","w")
for line in fp1:
fp2.write(line)
fp1.close()
fp2.close()
fp2=open("dest.txt","r")
print("dest.txt")
print(fp2.read())
# Read from the source file and write to the destination file
with open("source.txt", "r") as fp1, open("dest.txt", "w") as fp2:
for line in fp1:
fp2.write(line)
dest.txt
python python
java python
c java
RESULT:
Thus, a Python Program copy the content of one file into another was
executed and the output was obtained.
9 b) WORD COUNT -FILE
AIM:
To write a Python Program to find the words in a text file and the number of
occurrence of the words.
ALGORITHM:
# WORD COUNT
content = fp1.read()
print("source.txt")
print(content)
wordcount = {}
words = content.split()
for w in words:
if w not in wordcount:
wordcount[w] = 1
else:
wordcount[w] += 1
print(wordcount)
fp1=open("source.txt","r")
wordcount={}
content=fp1.read()
print("source.txt")
print(content)
words=content.split()
for w in words:
if w not in wordcount:
wordcount[w]=1
else:
wordcount[w]+=1
print (wordcount)
fp1.close()
OUTPUT:
source.txt
python python
java python
c java
RESULT:
Thus, a Python Program to find the words in a text file and the number
of occurrence of the words was executed and the output was obtained.
9 C) LONGEST WORD
AIM:
To write a Python Program to find the longest word in a file.
ALGORITHM:
1. Start
2. Open the file from the specified path and read the data using read()
method
3. Find the longest word using max() function and print the result
4. Stop the program
PROGRAM:
def longest_word(filename):
with open (filename,’r’)as infile:words
= infile.read().split()
Max_len = len(max(words,key=len))
return [word for word in words if len(word)==max_len]
print(longest_word(“F:\Data.txt”)
# Example usage
print(longest_word("F:\\Data.txt"))
OUTPUT:
[‘collection’]
RESULT:
Thus a Python Program to find the largest word in a file was executed
and the output was obtained.
10. IMPLEMENTING REAL TIME/TECHNICAL APPLICATIONS
USING EXCEPTION HANDLING
AIM:
To write a Python Program to find validate voter’s age validity using
Exception Handling.
ALGORITHM:
1: Start
2: Read the value of age of the person.
3: if (Age > 18) then 3a else 3b.
3a: Print Eligible to vote.
3b: Print not Eligible to vote.
4: if valid age not entered raise exception
PROGRAM:
try:
age=int(input("enter your age"))
if(age>=18):
print ("eligible to vote")
else:
print("not eligible to vote")
except:
print("enter a valid age")
else:
print("Not eligible to vote") # If age is less than 18
except ValueError:
print("Enter a valid age") # Handle the case where input is not an integer
OUTPUT:
RESULT:
Thus, a Python Program to find validate voter’s age validity using
Exception Handling was executed and the output was obtained.
10 b) DIVIDE BY ZERO ERROR USING EXCEPTION HANDLING
AIM:
To write a Python Program to find handle divide by zero error using
exception handling
ALGORITHM:
1. Start
2. Read the value for n,d and c
3. Calculate Quotient = n/(d-c) in try block
4. If ZeroDivisionError arise print division by zero
5. Stop
PROGRAM:
RESULT:
Thus, a Python Program handle divide by zero error using Exception
Handling was executed and the output was obtained.
10 c) STUDENT MARK RANGE VALIDATION
AIM:
To write a Python Program to perform student mark range validation
ALGORITHM:
1. Start
2. Read student mark from user
3. If mark is in between 0 and 100 print in range
4. Otherwise print out of range
5. Stop
PROGRAM:
OUTPUT:
RESULT:
Thus, a Python Program student mark validation was executed and the
output was obtained.
11. EXPLORING PYGAME
AIM:
import pygame
# Initialize Pygame
pygame.init()
OUTPUT:
RESULT:
Thus, the bouncing ball using pygame has been successfully executed and
output is obtained.
12. SEARCHING AND SORTING
12 a) Binary Search
AIM:
To write a Python Program to find whether the given number is present in a
list using binary search.
ALGORITHM:
# BINARY SEARCH
# Note: Avoid using 'list' as a variable name since it's a built-in type in Python.
numbers = [11, 17, 20, 23, 29, 33, 37, 41, 45, 56]
X = int(input("Enter the number to be searched: "))
l=0
h = len(numbers) - 1
while l <= h:
mid = (l + h) // 2
if X == numbers[mid]:
print("Element found at index:", mid)
break
elif X < numbers[mid]:
h = mid - 1
else:
l = mid + 1
else:
print("Element not found")
OUTPUT:
Element found
RESULT:
Thus, a Python Program to find whether the given is present in a list
using binary search was executed and the output was obtained.
12b) Insertion Sort
AIM:
To write a Python Program to sort the elements in the list using Insertion
Sort.
ALGORITHM:
# Insertion Sort
a = [16, 19, 11, 15, 10, 12, 14]
print("Original List:", a)
print("Sorted List:", a)
OUTPUT:
RESULT:
Thus, a Python Program to sort the elements in the list using Insertion
Sort was executed and the output was obtained.
13. CREATE A MODULE
AIM:
ALGORITHM:
1. Start
2. Create mymodule.py
3. Import the mymodule.py
4. Print age of the person
5. STOP
PROGRAM:
mymodule.py
# mymodule.py
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
"country": "Norway"
# new.py
import mymodule
a = mymodule.person1["age"]
print(a)
print(a)
OUTPUT:
36
RESULT:
Thus, a Python Program to create and import module was executed and
the output was obtained.