GE3171-PSPP Manual-1-1-1
GE3171-PSPP Manual-1-1-1
Date:
Aim :
To calculate the Electricity consumptions for October month EB meter reading, and
November month EB meter reading using the following criteria
Algorithm:
Step 3: Calculate number of units consumed by user by subtracting November month EB meter
Step 5: If consumption between 100 units and 500 units calculate the EB bill 2 Rupees per unit
Step 6: If consumption > 500 units calculate the EB bill 4.5 Rupees per unit
Flowchart:
Output:
Result:
Thus, Electricity consumptions for October and November month EB meter reading has
been calculated and output is verified successfully.
Ex.No:1b RETAIL SHOP BILLING
Date:
Aim :
To develop a flowchart for calculating the retail shop billing with following
specification
Algorithm:
Step 2: Make the Bill amount pre set to 0 and Get the quantity of purchase
Step 3: Get the rate of the item from user and prepare a bill by multiplying the quantity and rate
and it with bill
Step 4: Make a loop to evolve around and get exit code of (0) if user wants to close the billing
process
Step 5: If the billing process is completed display the bill amount to the user else continue to step
1
Flowchart:
Output:
Result:
Thus, retail shop billing has been calculated successfully and output is verified.
Ex.No:1c SUM OF SERIES
Date:
Aim :
Algorithm:
Step 1: Create a variable Sum and preset to 0, create a looping variable i and present to 1
Step 3: create loop structure which exist till the looping variable i reaches the n value
Output:
Result:
Thus the sum of the arithmetic series has been created successfully and output is
verified.
Ex.No:2a SWAPPING OF NUMBERS
Date:
Aim:
To write a python program to swap the two numbers without using a third variable
Algorithm:
Step 1: Start
Step 2: Read the values of a and b
Step 3: Calculate the values of a = a+ b
Step 4: Calculate the values of b = a- b
Step 5: Calculate the values of a = a- b
Step 6: Print a, b
Step 7: Stop
Flowchart:
Start
Read
a,b
a=a+b
b=a-b
a=a-b
Print
a,b
Stop
Program:
Output:
Result:
Thus, swapping of two numbers without using third variable program was successfully
executed and output verified.
Ex.No:2b CALCULATE TOTAL DISTANCE
Date:
Aim:
Algorithm:
Step 1: Start
Step 2: Read the values of a=1, b=350 and c=314
Step 3: Calculate the value of distance = a+b+c
Step 4: Print the value of distance
Step 5: Stop
Flowchart:
Start
Read a=1,
b=350, c=314
Distance=a+b+c
Print
distance
Stop
Program:
a=1
b=350
c=314
distance=a+b+c
print(“Distance travelled by the person is”,distance)
Output:
Result:
Thus, the distance travelled by the person program was successfully executed and output
verified.
Ex.No:2c ROTATING NUMBERS
Date:
Aim:
Algorithm:
Step 1: Start
Step 2: Read the values of a=10, b=20 and c=30
Step 3: Assign the values of c to d
Step 4: Assign the values of b to c
Step 5: Assign the values of a to b
Step 6: Assign the values of d to a
Step 7: Assign the values of c to e
Step 8: Assign the values of b to c
Step 9: Assign the values of a to b
Step 10: Assign the values of e to a
Step 11: Print a,b, c
Step 12: Stop
Flowchart:
Start
Read
a=10,b=20,c=30
d=c
c=b
b=a
a=d
e=c
c=b
b=a
a=e
Print a,b,c
Stop
Program:
a=10
b=20
c=30
d=c
c=b
b=a
a=d
e=c
c=b
b=a
a=e
print(a,b,c)
Output:
20,30,10
Result:
Thus, the number rotation program was successfully executed and verified.
Ex.No:3a Pyramid Pattern
Date:
Aim:
To write a python program for printing following pattern.
(i) *
**
***
****
*****
(ii)
*
***
*****
Algorithm:
Program:
for i in range(1,6):
print()
for j in range(i):
print("*",end='')
Program:
n=3
for i in range(n):
for j in range(n - i - 1):
print(' ', end='')
for k in range(2 * i + 1):
print('*', end='')
print()
FLOWCHART:
(i)
START
NO For i in
range(1,6)
Yes NO
For j in
range(i)
Yes
Print *
STOP
START
(ii)
For i in range(3) No
yes
yes
For j in range(3-i-
1) No
yes
Yes
Print “”
For j in range(3-i-1)
No
Yes
Print “*”
Print new
line
STOP
OUTPUT:
RESULT:
Thus, the program for printing pattern is executed and the output is obtained.
Ex.No:3b NUMBER PATTERN
Date:
Aim:
To write a python program for printing following Number pattern.
1
11
112
1123
11235
Algorithm:
Program:
n=5
for i in range(0,n):
n1,n2=0,1
for j in range(0,i+1):
print(n2,end="")
n3=n1+n2
n1=n2
n2=n3
print()
FLOWCHART:
Start
N=5,N1=0,N2=1
For i in
rane(0,n)
Yes
For j in
No rane(0,i+1) NO
Yes
Print n1
N3=n1
+n2
N1=n2
N2=n3
STOP
Output:
RESULT:
Thus, the program for printing Number pattern is executed and the output is obtained.
Ex.No:3c Number pattern
Date:
Aim:
To write a python program for printing following Number pattern.
1
21
321
4321
54321
Algorithm:
PROGRAM:
rows = 6
for i in range(1, rows):
for j in range(i, 0, -1):
print(j, end=' ')
print("")
FLOWCHART:
START
Rows=6
For i in
range(1,rows)
No
Yes
For j in
range(I,0,-1)
Yes Yes No
Print j
Print next
line
STOP
Output:
RESULT:
Thus, the program for printing Number pattern is executed and the output is obtained
Ex.No:4a SQUARE ROOT OF A GIVEN NUMBER
Date:
Aim:
To write a python program to find the square root of a number using functions
Algorithm:
Step 1: Start
Step 2: Read n
Step 3: Call the function sqroot
Step 4: Stop
Function sqroot:
def sqroot(n):
root=n/2
for I in range(10):
root=(root+n/root)/2
print(“The square root of “, n , “ is : ”, root)
N=int(input(“enter a number”))
Sqroot(n)
Output:
Enter a number: 25
The square root of 25 is: 5
Result:
Thus a python program to find the square root of a number using functions is executed
and the output is verified.
Ex.No:4b FACTORIAL OF A GIVEN NUMBER
Date:
Aim:
To write a python program to compute the factorial of a given number using functions
Algorithm:
Step 1: Start
Step 2: Read n
Step 3: call the function fact
Step 4: Stop
Function fact:
output:
Result:
Aim:
To write a python program to compute the sum of elements in an array of n elements
using functions.
Algorithm:
Step 1: start
Step 2: Initialize the value of sum as 0
Step 3: Read n
Step 4: print the elements of the array
Step 5: for each value of j in the range(0,n), read elements and add the element to a using
append() function
Step 6: print the value of the array
Step 7: Call the function sum_array
Step 8: Stop
Function sum_array:
Step 1: For each value of I in a, calculate the value of sum as sum=sum+I and increment the
value of I by 1
Step 2: print the sum value
Program:
Sum=0
a=[]
n= int(input(“enter No. of elements:”)
print(“Elements in the array is:”)
for j in range (0,n):
element= int(input())
a.append(element)
print(“Array is : “,a)
sum_array(sum)
def sum_array(sum):
for I in a:
sum+=i
i+=1
print(“Sum of the elements in the array is :”,sum)
OUTPUT:
enter No. of elements: 4
Elements of the array
2
3
4
5
Array is [2,3,4,5]
Sum of the elements in the array is : 14
Result:
Thus a python program to compute the sum of elements in an array of n elements using
functions is executed and the output is verified.
Ex.No:4d LARGEST ELEMENT IN THE ARRAY
Date:
Aim:
To write a python program to find the largest element in an array using functions
Algorithm:
Step 1: Start
Step 2: declare a=[]
Step 3: Read n
Step 4: for each value of I in range (0,n), read elements and add the element to a using append()
function.
Step 5: print the values of the array
Step 6: call the function greatest
Step 7: stop
Function greatest:
def largest(n):
largest= a[0]
for j in range(1,n):
if(a[j]>largest):
largest=a[j]
else:
continue
print(“ largest element is : “, largest)
OUTPUT:
Result:
Thus a python program to find the largest element in an array using functions is executed
and the output is verified.
Ex.No:4e LINEAR SEARCH
Date:
Aim:
To write a python program to find whether an element is present in the array using linear
search.
Algorithm:
Step 1: start
Step 2: declare an array a[]
Step 3: read the value of n
Step 4: for each value of I in range(0,n), read the elements of the array
Step 5: print the elements of the array
Step 6: call the function linear_search
Step 7: stop
Function linear_search:
Step 1: for the value I in range (0,len(a)-1), if the value of search is equal to a[i], then print the
element is present in the array at the position i
Step 2: assign the value of j=1 and break the loop
Step 3: else assign the value of j=0
Step 4: if the value of j is equal to 0, print the element is not present in the list
Program:
a=[]
n=int(input(“Enter the number of elements in the array: “ )
print(“Enter the elements of the array:”)
for I in range(0,n):
element=int(input())
a.append(element)
print(“The array is :”,a)
search=int(input(“Enter the element to be searched :”))
linear(search)
def linear(search):
for I in range(0,len(a)-1):
if(search==a[i]):
print(“The element is found at “, I , “ position”)
j=1
break
else
j=0
if(j==0):
print(“The element is not present in the list”)
OUTPUT:
Result:
Thus a python program to find whether an element is present in the array using linear
search is executed and the output is verified.
Ex.No:4e BINARY SEARCH
Date:
Aim:
To write a python program to find whether an element is present in the array using binary
search.
Algorithm:
Step 1: Start
Step 2: declare the array a[]
Step 3: read the value of n
Step 4: for each value of I in range(0,n), read the elements and add the elements to the array
Step 5: print the elements in the array
Step6: read the value to be searched
Step 7: call the function binary
Step 8: stop
Function binary:
def binary(search):
start=0
stop=len(a)-1
j=0
while(start<=stop):
mid=(start+stop)//2
if(search==a[mid]):
print(“Element is present at :”, mid ,” position in the list”)
j=1
break
elif(search>a[mid]):
start=mid+1
else:
stop=mid-1
if(j==0)
print(“Element is not in the list”)
Output:
Enter the number of elements: 4
Enter the elements of the array:
2
3
4
5
The Array is : [2,3,4,5]
Enter the element to be searched: 3
Element is present at 2 position in the list
Result:
Thus a python program to find whether an element is present in the array using binary
search is executed and the output is verified
Ex.No:5a OPERATIONS OF SETS
Date:
Aim:
Algorithm:
Program:
L1 = {'Pitch', 'Syllabus', 'Script', 'Grammar', 'Sentences'};
# set union
# set intersection
# set difference
Output:
Result:
The program on operations in sets are executed and the output is verified.
Ex.No:5b OPERATIONS ON DICTIONARY
Date:
Aim:
Algorithm:
Program:
my_dict = {}
# Output: Jack
print(my_dict['name'])
# Output: 26
print(my_dict.get('age'))
# my_dict.get('address')
# my_dict['address']
Output: Jack 26
How to change or add elements in a dictionary
# update value
my_dict['age'] = 27
# add item
my_dict['address'] = 'Downtown'
# create a dictionary
# Output: 16
print(squares.pop(4))
# Output: (1, 1)
print(squares.popitem())
# Output: {2: 4, 3: 9}
print(squares)
squares.clear()
# Output: {}
print(squares)
del squares
# Throws Error
# print(squares)
Output :
16
{1: 1, 2: 4, 3: 9, 5: 25}
(1, 1)
{2: 4, 3: 9, 5: 25}
{2: 4, 3: 9}
{}
Result:
The program on operations on dictionary is executed and the output is verified.
Ex.No:6a LIBRARY MANAGEMENT USING LIST
Date:
Aim:
To develop a python application to maintain the books for CSE department in library. To
create a list for storing the books and the quantity available in the library.
Algorithm:
Flowchart:
Program:
book=[]
qty=[]
for i in range(0,n):
book.append(b)
q=int(input("Enter Count:"))
qty.append(q)
for i in range(0,n):
print("Book name:",book[i])
print("Quantity:",qty[i])
Output:
Enter Count:12
Enter Count:20
Enter Count:15
Enter Count:23
Quantity: 12
Book name: C
Quantity: 20
Quantity: 15
Quantity: 17
Quantity: 23
Result:
Thus, the program for storing and displaying the books of CSE department in the Library
is executed and the output is verified successfully.
Ex.No: 6b PROGRAM FOR TUPLES
Date:
Aim:
To write a python program for maintaining the list of items for different constructions a
civil engineer carries out.
Algorithm:
Flowchart:
Program:
cb=len(concrete_building)
for i in range(0,cb):
print(concrete_building[i])
ir=len(iron_structure)
for i in range(0,ir):
print(iron_structure[i])
s=len(shed)
cb=len(concrete_building)
for i in range(0,cb):
print(concrete_building[i])
ir=len(iron_structure)
print(iron_structure[i])
s=len(shed)
print(shed[i])
Output:
Sand
Bricks
Wood
Steel
Cement
Color Sheets
Cooling Sheets
Result:
Thus, the program for storing the list of items for different constructions a civil engineer
carries out is executed and the output is verified successfully.
Ex.No: 6c STUDENT MARKLIST
Date:
Aim:
To write a python program to collect the students marks in 5 subjects and calculate total
marks and percentage of marks of each student. Also find the student who banked the first place.
Algorithm:
Flowchart:
Program:
student1=[]
n=5
for i in range(0,n):
student1.append(ele1)
print(student1)
student2=[]
for i in range(0,n):
student2.append(ele2)
print(student2)
student3=[]
for i in range(0,n):
student3.append(ele3)
print(student3)
student4=[]
for i in range(0,n):
student4.append(ele4)
print(student4)
student5=[]
for i in range(0,n):
ele5=int(input("Enter student5 marks for 5 subject:"))
student5.append(ele5)
print(student5)
student_mark1=sum(student1)
percentage_student1=student_mark1/500*100
print("Student1%",percentage_student1)
student_mark2=sum(student2)
percentage_student2=student_mark2/500*100
print("Student2%",percentage_student2)
student_mark3=sum(student3)
percentage_student3=student_mark3/500*100
print("Student3%",percentage_student3)
student_mark4=sum(student4)
percentage_student4=student_mark4/500*100
print("Student4%",percentage_student4)
student_mark5=sum(student4)
percentage_student5=student_mark5/500*100
print("Student5%",percentage_student5)
percentage=[]
percentage.append(percentage_student1)
percentage.append(percentage_student2)
percentage.append(percentage_student3)
percentage.append(percentage_student4)
percentage.append(percentage_student5)
First_marks=max(percentage)
print("First place mark is :",First_marks)
Output:
Student1% 91.60000000000001
Student2% 86.6
Student3% 97.0
Student4% 67.60000000000001
Student5% 67.60000000000001
Result:
Thus, the program for collecting the students marks in 5 subjects and calculating total
marks and percentage of marks of each student is executed and the output is verified
successfully.
Ex.No: 6d RETAIL SHOP BILLING
Date:
Aim:
To write a python program to simulate the billing process on a Retail shop. To include
products like pen, notebook, soap and get the quantity and provide discount if the total amount is
greater than Rs.1000.
Algorithm:
print("*Available Items*")
total_amt=int(soap*50+notebook*100+pen*100)
if(total_amt>1000):
discount=total_amt*0.1
final_amt=total_amt-discount
else:
Output:
Sample:1
*Available Items*
1. Soap - Cost - Rs.50
Sample 2:
*Available Items*
Result:
Thus, the program for performing retail bill shopping by providing discount is executed
and the output is verified successfully.
Ex.No:7a FILE HANDLING-COPY FROM ONE FILE TO ANOTHER
Date:
Aim:
To write a python program that read a file and copy in another file.
Algorithm:
Program:
file1=open("C:/Users/WDSCBELT231/Desktop/file1.txt","r")
with open("C:/Users/WDSCBELT231/Desktop/file2.txt","w") as file2:
line = file1.read()
file2.write(str(line))
file2.close()
file1.close()
Output:
Result:
Thus, a python program that read a file and copy the contents in another file has been
executed successfully.
Ex.No:7b FILE HANDLING- WORD COUNT
Date:
Aim:
To write a python program that counts number of words in a file.
Algorithm:
Step 1: Create a variable to store the total number of words in the file.
Step 2: Open the text file in read-only mode using the open() function.
Step 3: Read the content of the file using the read() function and store it in a new variable.
Step 4: Split the data stored in the data variable into separate lines using the split() function
and then storing them in a new variable.
Step 5: Add the length of the lines in number_of_words variable.
Program:
number_of_words = 0
with open("C:/Users/WDSCBELT231/Desktop/file1.txt","r") as file:
data = file.read()
lines = data.split()
number_of_words += len(lines)
print("The total number of words in file1 is:",number_of_words)
Output:
Result:
Thus, a python program that counts number of words in a file has been executed
successfully.
Ex.No:8 EXCEPTION HANDLING- DIVIDE BY ZERO ERROR
Date:
Aim:
To write a python program to divide two numbers, also ensure that denominator is not
zero.
Algorithm:
Program:
try:
a = int(input("Please enter the numerator: "))
b = int(input("Please enter the denominator: "))
result = a / b
except (ZeroDivisionError, ValueError):
print("Please enter valid integers. The denominator can't be zero")
else:
print(result)
finally:
print("Inside the finally clause")
Output:
Please enter the numerator: 25
Please enter the denominator: 5
5.0
Inside the finally clause
Result:
Thus a python program to divide two numbers, also ensure that denominator is not zero
has been executed successfully.
Ex.No:9 EXCEPTION HANDLING- VOTER'S AGE VALIDITY
Date:
Aim:
To write a python program to collect details for Voter ID, ensure that each enrollment age
is above 17.
Algorithm:
Program:
try:
name = str(input("Please enter the name: "))
age = int(input("Please enter the age: "))
assert age > 17
city = str(input("Please enter the city: "))
except (AssertionError, ValueError):
print("Please enter valid age. The candidate should be above 17")
else:
print(f"The candidate name is {name}. His age is {age}. He belongs to {city} constituency")
finally:
print("Inside the finally clause")
Output:
Please enter the name: John
Please enter the age: 19
Please enter the city: Chennai
The candidate name is John. His age is 19. He belongs to Chennai constituency
Inside the finally clause
Result:
Thus, a python program to collect details for Voter ID has been executed successfully.
Ex.No.10 CASE STUDY
Date:
Aim:
To develop a simple Catching the ball game using Python and TKinter.
Algorithm:
Step1: Use Tkinter package in python for building GUI(Graphical user interface).
Step2: Use Canvas for drawing objects in Python – Canvas is a rectangular area intended for
drawing pictures or other complex layouts. We can place graphics, text, widgets or frames on
Canvas.
Syntax: w = Canvas ( master, option=value, ... )
Parameters:
master - This represents the parent window.
options - List of most commonly used options for this widget.
These options can be used as key-value pairs separated by commas.
Example- width, height etc.
Step 3: Use canvas.create_oval for creating the ball. create_oval creates a circle or an ellipse at
the given coordinates. It takes two pairs of coordinates; the top left and bottom right corners of
the bounding rectangle for the oval.
Syntax: oval = canvas.create_oval(x0, y0, x1, y1, options)
Step 5: Use canvas.move for moving the ball or bar. canvas.move enables the object to move
with the specified (x, y) coordinates.
Syntax: move=canvas.move(name of object, x, y)
Note: *Take x=0 for moving the ball in vertical direction only and take y=0 for moving the bar
in horizontal direction only. *Disappear the ball when it touches the ground or the bar using
canvas.delete(object).
Step 6: Use Button for moving the bar in forward or backward and then apply action event on
it.
# Python code for catching the ball game
else:
# disappear the ball
canvas.delete('dot1')
bar.delete_bar(self)
def delete_bar(self):
canvas.delete('dot2')
button4 = Button(canvas2,text="EXIT",bg="green",
command=lambda:exit_handler(root2))
button4.pack()
# Main function
def main():
global score,dist
score = 0
dist = 0
# defining the dimensions of bar
bar1=bar(canvas,5,560,45,575)
button2 = Button(canvas,text="<==",bg="green",
command=lambda:bar1.move_bar(0))
button2.place(x=260,y=580)
Result:
Thus, the python program for Catching the ball game was implemented and verifiedsuccessfully.