[go: up one dir, main page]

0% found this document useful (0 votes)
6 views75 pages

GE3171-PSPP Manual-1-1-1

The document outlines various programming exercises, including calculating electricity bills based on consumption, retail shop billing, arithmetic series sums, and number manipulations using Python. Each exercise includes an aim, algorithm, flowchart, program code, output, and result verification. The focus is on implementing algorithms through Python functions to solve mathematical and logical problems.
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)
6 views75 pages

GE3171-PSPP Manual-1-1-1

The document outlines various programming exercises, including calculating electricity bills based on consumption, retail shop billing, arithmetic series sums, and number manipulations using Python. Each exercise includes an aim, algorithm, flowchart, program code, output, and result verification. The focus is on implementing algorithms through Python functions to solve mathematical and logical problems.
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
You are on page 1/ 75

Ex.

No:1a ELECTRICITY BILLING

Date:

Aim :

To calculate the Electricity consumptions for October month EB meter reading, and
November month EB meter reading using the following criteria

If consumption < 100 units


Free
If consumption between 100 units and 500 units
2 Rupees per unit
If consumption > 500 units 4.5 Rupees per unit

Algorithm:

Step 1: Get the October month EB meter reading from user

Step 2: Get the November month EB meter reading from user

Step 3: Calculate number of units consumed by user by subtracting November month EB meter

reading and October month EB meter reading

Step 4: If consumption < 100 units Make the EB bill Free

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

a. Include 3 Quantity from each item in the list


b. Soap, Note book, Pen, Etc
c. If bill exceeds Rs.1000 offer 10% discount

Algorithm:

Step 1: Get the item user wants to buy

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 :

To draw a flowchart to calculate the Sum of the arithmetic series 13 +23+33+……+n3


using looping structure

Algorithm:

Step 1: Create a variable Sum and preset to 0, create a looping variable i and present to 1

Step 2: Get the n (ending) value from the user

Step 3: create loop structure which exist till the looping variable i reaches the n value

Step 4: Calculate cube of i and add it to sum

Step 5: increment looping variable i by one (each time)

Step 6: if i<=n continue to step 4, else display the sum to user


Flowchart:

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:

a=int(input(“enter the value of a:”)


b= int(input(“enter the value of b:”)
a=a+b
b=a-b
a=a-b
print(a,b)

Output:

enter the value of a: 45


enter the value of b: 55
55 45

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:

To write a python program to compute the distance travelled by a person.

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:

Distance travelled by the person is 665

Result:

Thus, the distance travelled by the person program was successfully executed and output
verified.
Ex.No:2c ROTATING NUMBERS

Date:

Aim:

To write a python program to rotate the values of a, b and c twice

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:

Step 1: Start the program.


Step 2: Let i be an integer number.
Step 3: Let j be an integer number.
Step 4: Repeat step 5 to 7 until all value parse.
Step 5: Set i=1 and check i<6;
Step 6: Set j=1 and check j<=i;
Step 7: Print “*”.
Step 8: Stop the program.
Algorithm:

Step 1: Start the program.


Step 2: Declare the number n=3.
Step 3: Let i be an integer number.
Step 4: Let j be an integer number.
Step 5: Let k be an integer number
Step 6: Repeat step 7 to 10 until all value parse.
Step 7: Set i=0 and check i<n;
Step 8: Set j=0 and check j<n-1-i;
Step 9: Set k=0 and check k<2*i+1;
Step 10: Print “*”.
Step 11: Stop the program.

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:

Step 1: Start the program.


Step 2: Declare the number n=5 and n1=0, n2=1
Step 3: Let i be an integer number.
Step 4: Let j be an integer number.
Step 5: Repeat step 5 to 7 until all value parse.
Step 5: Set i=0 and check i<n;
Step 6: Set j=0 and check j<=i+1;
Step 6.1: print n2
Step 6.2:n3=n1+n2
Step 6.3:n1=n2
Step 6.4:n2=n3
Step 7: Stop the program

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

print

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:

Step 1: Start the program.


Step 2: Declare the value rows=6
Step 3: Let i be an integer number.
Step 4: Let j be an integer number.
Step 5: Repeat step 5 to 7 until all value parse.
Step 6: Set i=1 and check i<rows;
Step 7: Set j=i and check j>-1;
Step 8: Print j.
Step 9: Stop the program.

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:

Step 1: Assign the value of root as root = n/2


Step 2: for each value of I in range(10), calculate the value of root as root=(root+n/root)/2
Step 3: Print the value of root
Program:

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:

Step 1: Assign the value of i=1, fact =1


Step 2: while the value of I is less than or equal to n, calculate the value of fact as fact = fact *I,
and increment the value of I by 1
Step 3: print fact
Program:

n= int(input(“Enter the number:”))


fact(n)
def fact(n):
i=1
fact=1
while(i<=n):
fact*=i
i+=1
print(“The Factorial of “, n, “ is: “,fact)

output:

Enter the number: 4


The factorial of 4 is: 24

Result:

Thus a python program to compute the factorial of a given number using


functions is executed and output is verified successfully.
Ex.No:4c SUM OF AN ARRAY
Date:

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:

Step 1: Assign the value of the largest=a[0]


Step 2: for each value of j in range(1,n), if a[j] is greatest than largest, then assign the value of
the a[j] to largest. Repeat through step 2
Step 3: print the largest value
Program:
a=[]
n=int(input(“Enter the no. of elements”))
print(“Enter the elements of the array”)
for I in range (0,n):
element=int(input())
a.append(element)
print(“Elements in the array is : “, a)
largest(n)

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:

Enter the no. of elements: 4


Elements in the array is: [2, 3, 4, 5]
Largest element is: 5

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:

Enter the number of elements in the array: 5


Enter the elements of the array:
2
3
4
5
6
The array is : [2, 3, 4, 5, 6]
Enter the element to be searched : 6
The element is found at 4 position

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:

Step1: assign the value of start=0, stop= len(a)-1, j=o


Step 2: while the value of start is less than or equal to stop, assign the value of
mid=(start+stop)//2
Step 3: if the value of search is equal to a[mid] then print the element is present, assign the value
of j as 1 and break the loop
Step 4: else if the value of search is greater than s[mid] then assign start=mid+1, repeat through
step 2
Step 5: else assign stop=mid-1, repeat through step 2
Step 6: if the value of j is equal to j=0 then print the element is not present in the list
Program:
a=[]
n=int(input(“Enter the number of elements: “))
print(“Enter the elements in 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: “))
binary(search)

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:

To Implement operations in a set using Components of a python Language.

Algorithm:

Step1: Start the program


Step2: Create a L1 and L2 sets
Step3: Perform union operation on sets
Step4: Perform intersection on sets
Step5: Perform difference on two sets
Step6: Perform symmetric on two sets
Step7: Display all the results
Step8: Stop the process

Program:
L1 = {'Pitch', 'Syllabus', 'Script', 'Grammar', 'Sentences'};

L2 = {'Grammar', 'Syllabus', 'Context', 'Words', 'Phonetics'};

# set union

print("Union of L1 and L2 is ",L1 | L2)

# set intersection

print("Intersection of L1 and L2 is ",L1 & L2)

# set difference

print("Difference of L1 and L2 is ",L1 - L2)

# set symmetric difference

print("Symmetric difference of L1 and L2 is ",L1 ^ L2)

Output:

Union of L1 and L2 is {'Words', 'Pitch', 'Sentences', 'Phonetics', 'Script', 'Grammar', 'Syllabus',


'Context'}

Intersection of L1 and L2 is {'Grammar', 'Syllabus'}


Difference of L1 and L2 is {'Script', 'Pitch', 'Sentences'}

Symmetric difference of L1 and L2 is {'Words', 'Context', 'Script', 'Pitch', 'Sentences',


'Phonetics'}

Result:
The program on operations in sets are executed and the output is verified.
Ex.No:5b OPERATIONS ON DICTIONARY

Date:

Aim:

To Implement operations on dictionaries using Components of a Language in python.

Algorithm:

Step1: Start the program


Step2: Empty dictionary in the name of my_dict
Step3: Perform access elements in the dictionary
Step4: Perform change the elements in the dictionary
Step5: Perform remove the elements in the dictionary
Step6: Perform delete the elements in the dictionary
Step7: Display all the results
Step8: Stop the process

Program:

How to create a dictionary


# empty dictionary

my_dict = {}

How to access elements from a dictionary

my_dict = {'name':'Jack', 'age': 26}

# Output: Jack
print(my_dict['name'])

# Output: 26

print(my_dict.get('age'))

# Trying to access keys which doesn't exist throws error

# my_dict.get('address')

# my_dict['address']

Output: Jack 26
How to change or add elements in a dictionary

my_dict = {'name':'Jack', 'age': 26}

# update value
my_dict['age'] = 27

#Output: {'age': 27, 'name': 'Jack'}


print(my_dict)

# add item
my_dict['address'] = 'Downtown'

# Output: {'address': 'Downtown', 'age': 27, 'name': 'Jack'}


print(my_dict)

#Output: {'age': 27, 'name': 'Jack'}


{'age': 27, 'address': 'Downtown', 'name': 'Jack'}

How to delete or remove elements from a dictionary

# create a dictionary

squares = {1:1, 2:4, 3:9, 4:16, 5:25}


# remove a particular item

# Output: 16

print(squares.pop(4))

# Output: {1: 1, 2: 4, 3: 9, 5: 25}


print(squares)
# remove an arbitrary item

# Output: (1, 1)

print(squares.popitem())

# Output: {2: 4, 3: 9, 5: 25}


print(squares)
# delete a particular item
delsquares[5]

# Output: {2: 4, 3: 9}
print(squares)

# remove all items

squares.clear()

# Output: {}

print(squares)

# delete the dictionary itself

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:

Step 1:Start the program


Step 2:Create two empty list for storing the book name and the quantity.
Step 3:Get the book count as input from the user.
Step 4:Using for loop ranging from the index position 0 to the book count, get the book name
and quantity from the user and store in the list.
Step 5:Use list.append() function to store the values into the list.
Step 6: Using for loop print the book name and the quantity of each books available in the
library.
Step 7: Stop the program

Flowchart:
Program:

print("*****Storing CSE Books List*****")

book=[]

qty=[]

n=int(input("Enter Book Count:"))

for i in range(0,n):

b=str(input("Enter Book Name:"))

book.append(b)

q=int(input("Enter Count:"))

qty.append(q)

print("*****List of CSE Books in Library with Quantity*****")

for i in range(0,n):

print("Book name:",book[i])

print("Quantity:",qty[i])

Output:

*****Storing CSE Books List*****

Enter Book Count:5

Enter Book Name:Python

Enter Count:12

Enter Book Name:C

Enter Count:20

Enter Book Name:Java

Enter Count:15

Enter Book Name:DBMS


Enter Count:17

Enter Book Name:Operating System

Enter Count:23

*****List of CSE Books in Library with Quantity*****

Book name: Python

Quantity: 12

Book name: C

Quantity: 20

Book name: Java

Quantity: 15

Book name: DBMS

Quantity: 17

Book name: Operating System

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:

Step 1:Start the program


Step 2:Using tuples, get the items for concrete building and store it in concrete_building.
Step 3:Get the length of concrete_building and using for loop, print the values stored in
concrete_building.
Step 4:Using tuples, get the items for iron structure and store it in iron_structure.
Step 5:Get the length of iron_structureand using for loop, print the values stored in
iron_structure.
Step 6:Using tuples, get the items for iron structure and store it in shed.
Step 7:Get the length of shed and using for loop, print the values stored in shed.
Step 8:Stop the program.

Flowchart:
Program:

print("*** List of Items For Different Construction Items ***")

concrete_building=("Sand", "Bricks", "Wood", "Steel", "Cement")

cb=len(concrete_building)

print("*** Concrete_Building Items ***")

for i in range(0,cb):

print(concrete_building[i])

iron_structure=("Iron rods", "Steel Sheet", "Concrete")

ir=len(iron_structure)

print("*** Iron Structure Items ***")

for i in range(0,ir):

print(iron_structure[i])

shed=("Iron rods", "Color Sheets", "Cooling Sheets")

s=len(shed)

print("*** Shed Items ***")

for i in range (0,s):

print(shed[i])print("*** List of Items For Different Construction Items ***")

concrete_building=("Sand", "Bricks", "Wood", "Steel", "Cement")

cb=len(concrete_building)

print("*** Concrete_Building Items ***")

for i in range(0,cb):

print(concrete_building[i])

iron_structure=("Iron rods", "Steel Sheet", "Concrete")

ir=len(iron_structure)

print("*** Iron Structure Items ***")


for i in range(0,ir):

print(iron_structure[i])

shed=("Iron rods", "Color Sheets", "Cooling Sheets")

s=len(shed)

print("*** Shed Items ***")

for i in range (0,s):

print(shed[i])

Output:

*** List of Items For Different Construction Items ***

*** Concrete_Building Items ***

Sand

Bricks
Wood
Steel
Cement

*** Iron Structure Items ***


Iron rods
Steel Sheet
Concrete
*** Shed Items ***
Iron rods

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:

Step 1:Start the program


Step 2:Create an empty list for student1 and using for loop and append() function, get the marks
of 5 subject for student1.
Step 3:Repeat the process for getting the values for student2, student3, student4 and student5.
Step 4:Display the marks of each student.
Step 5:Calculate the total marks of each student using sum() function.
Step 6:Calculate the percentage of each student and store it in a variable.
Step 7:Append the percentage values of each student to a new list percentage[].
Step 8:Calculate the maximum percentage from the percentage[] list using max(percentage).
Step 9:Stop the program

Flowchart:
Program:

print("*** Students MarkList ***")

student1=[]

n=5

for i in range(0,n):

ele1=int(input("Enter student1 marks for 5 subject:"))

student1.append(ele1)

print(student1)

student2=[]

for i in range(0,n):

ele2=int(input("Enter student2 marks for 5 subject:"))

student2.append(ele2)

print(student2)

student3=[]

for i in range(0,n):

ele3=int(input("Enter student3 marks for 5 subject:"))

student3.append(ele3)

print(student3)

student4=[]

for i in range(0,n):

ele4=int(input("Enter student4 marks for 5 subject:"))

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:

*** Students MarkList ***

Enter student1 marks for 5 subject:98

Enter student1 marks for 5 subject:89

Enter student1 marks for 5 subject:78

Enter student1 marks for 5 subject:97

Enter student1 marks for 5 subject:96

[98, 89, 78, 97, 96]

Enter student2 marks for 5 subject:87

Enter student2 marks for 5 subject:89

Enter student2 marks for 5 subject:88

Enter student2 marks for 5 subject:85

Enter student2 marks for 5 subject:84

[87, 89, 88, 85, 84]

Enter student3 marks for 5 subject:98

Enter student3 marks for 5 subject:99

Enter student3 marks for 5 subject:97

Enter student3 marks for 5 subject:96

Enter student3 marks for 5 subject:95

[98, 99, 97, 96, 95]

Enter student4 marks for 5 subject:65

Enter student4 marks for 5 subject:54

Enter student4 marks for 5 subject:64


Enter student4 marks for 5 subject:78

Enter student4 marks for 5 subject:77

[65, 54, 64, 78, 77]

Enter student5 marks for 5 subject:68

Enter student5 marks for 5 subject:89

Enter student5 marks for 5 subject:87

Enter student5 marks for 5 subject:78

Enter student5 marks for 5 subject:69

[68, 89, 87, 78, 69]

Student1% 91.60000000000001

Student2% 86.6

Student3% 97.0

Student4% 67.60000000000001

Student5% 67.60000000000001

First place mark is : 97.0

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:

Step 1:Start the program.


Step 2:Using print statement, print the list of available items in the shop and its cost.
Step 3:Get the quantity needed for the user in each item.
Step 4:Calculate the total amount by multiplying the item and quantity.
Step 5:If the total amount exceeds Rs.1000, the user will get discount of 10%.
Step 6:Using If…Else statement provide the discount to the user.
Step 7: Print the total amount finally with or without discount.
Step 8:Stop the program.
Flowchart:
Program:

print("*** Retail Shop Billing ***")

print("*Available Items*")

print("1.Soap - Cost - Rs.50")

print("2.Notebook - Cost - Rs.100")

print("3.Pen - Cost - Rs.100")

print("Enter the quantity needed in each item")

soap=int(input("Soap Quantity Needed="))

notebook=int(input("Notebook Quantity Needed="))

pen=int(input("Pen Quantity Needed="))

total_amt=int(soap*50+notebook*100+pen*100)

print("Total amount you have purchased is:",total_amt)

if(total_amt>1000):

discount=total_amt*0.1

final_amt=total_amt-discount

print("Final Amount after Discount:",final_amt)

else:

print("OOPS ... You don't have discount!!!")

Output:

Sample:1

*** Retail Shop Billing ***

*Available Items*
1. Soap - Cost - Rs.50

2.Notebook - Cost - Rs.100

3.Pen - Cost - Rs.100

Enter the quantity needed in each item

Soap Quantity Needed=10

Notebook Quantity Needed=20

Pen Quantity Needed=25

Total amount you have purchased is: 5000

Final Amount after Discount: 4500.0

Sample 2:

*** Retail Shop Billing ***

*Available Items*

1.Soap - Cost - Rs.50

2. Notebook - Cost - Rs.100

3.Pen - Cost - Rs.100

Enter the quantity needed in each item

Soap Quantity Needed=2

Notebook Quantity Needed=3

Pen Quantity Needed=2

Total amount you have purchased is: 600

OOPS ... You don't have discount!!!

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:

Step 1: Start the program.


Step 2:Create a file file1.txt and open the file in the read mode.
Step 3:Another file file2.txt is opened in the write mode
Step 4:The contents of file1 is read using the read() and it is stored in the variable line.
Step 5:write() inserts the string in the file2 from file1.
Step 6:Close the file.
Step 7:Stop the program.

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:

The total number of words in file1 is: 12

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:

Step 1: Start the program.


Step 2: Declare two variables and get the inputs from the user (two numbers).
Step 3: Divide the two values by using division operator and store the result.
Step 4: If the entered data is not integer, throw an exception.
Step 5: If the remainder is 0, throw divide by zero exception.
Step 6: If no exception is there, return the result.
Step 7: Stop the program.

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:

Step 1: Start the program


Step 2: Declare the variables ‛name’ and ‛age’ and read the input from the user.
Step 3: Check Status age > 17.
Step 4: Create the variable city and read the input as string.
Step 5: If the entered data is not true then it throws an exception.
Step 6: If no exception is there, then it will print the details of the candidate.
Step 7: Stop the program.

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 4: Use canvas.create_rectangle for creating the bar.


create_rectangle creates a rectangle at the given coordinates. It takes two pairs of coordinates;
the top left and bottom right coordinates.
Syntax: oval = canvas.create_rectangle(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

# importing suitable packages


from tkinter import Tk,Button,Label
from tkinter import Canvas
from random import randint

# defining Tk from Tkinter


root = Tk()
root.title("Catch the ball Game")
root.resizable(False,False)

# for defining the canvas


canvas = Canvas(root, width=600, height=600)
canvas.pack()

# variable for the vertical distance


# travelled by ball
limit = 0

# variable for horizontal distance


# of bar from x-axis
dist = 5

# variable for score


score = 0

# Class for the Creating and moving ball


class Ball:

# for creation of ball on the canvas


def init (self, canvas, x1, y1, x2, y2):
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
self.canvas = canvas

# for creation of ball object


self.ball = canvas.create_oval(self.x1, self.y1, self.x2, self.y2,
fill = "red",tags = 'dot1')

# for moving the ball


def move_ball(self):
# defining offset
offset = 10
global limit

# checking if ball lands ground or bar


if limit >= 510:
global dist,score,next

# checking that ball falls on the bar


if(dist - offset <= self.x1 and
dist + 40 + offset >= self.x2):

# incrementing the score


score += 10

# disappear the ball


canvas.delete('dot1')

# calling the function for again


# creation of ball object
ball_set()

else:
# disappear the ball
canvas.delete('dot1')
bar.delete_bar(self)

# display the score


score_board()
return

# incrementing the vertical distance


# travelled by ball by deltay
limit += 1

# moving the ball in vertical direction


# by taking x=0 and y=deltay
self.canvas.move(self.ball,0,1)

# for continuous moving of ball again call move_ball


self.canvas.after(10,self.move_ball)

# class for creating and moving bar


class bar:
# method for creating bar
def init (self,canvas,x1,y1,x2,y2):
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
self.canvas = canvas

# for creating bar using create_rectangle


self.rod=canvas.create_rectangle(self.x1, self.y1, self.x2, self.y2,
fill="yellow",tags='dot2')

# method for moving the bar


def move_bar(self,num):
global dist

# checking the forward or backward button


if(num == 1):

# moving the bar in forward direction by


# taking x-axis positive distance and
# taking vertical distance y=0
self.canvas.move(self.rod,20,0)

# incrementing the distance of bar from x-axis


dist += 20
else:

# moving the bar in backward direction by taking x-axis


# negative distance and taking vertical distance y=0
self.canvas.move(self.rod,-20,0)

# decrementing the distance of bar from x-axis


dist-=20

def delete_bar(self):
canvas.delete('dot2')

# Function to define the dimensions of the ball


def ball_set():
global limit
limit=0

# for random x-axis distance from


# where the ball starts to fall
value = randint(0,570)

# define the dimensions of the ball


ball1 = Ball(canvas,value,20,value+30,50)

# call function for moving of the ball


ball1.move_ball()

# Function for displaying the score


# after getting over of the game
def score_board():
root2 = Tk()
root2.title("Catch the ball Game")
root2.resizable(False,False)
canvas2 = Canvas(root2,width=300,height=300)
canvas2.pack()

w = Label(canvas2,text="\nOOPS...GAME IS OVER\n\nYOUR SCORE = "


+ str(score) + "\n\n")
w.pack()

button3 = Button(canvas2, text="PLAY AGAIN", bg="green",


command=lambda:play_again(root2))
button3.pack()

button4 = Button(canvas2,text="EXIT",bg="green",
command=lambda:exit_handler(root2))
button4.pack()

# Function for handling the play again request


def play_again(root2):
root2.destroy()
main()

# Function for handling exit request


def exit_handler(root2):
root2.destroy()
root.destroy()

# Main function
def main():
global score,dist
score = 0
dist = 0
# defining the dimensions of bar
bar1=bar(canvas,5,560,45,575)

# defining the text,colour of buttons and


# also define the action after click on
# the button by calling suitable methods
button = Button(canvas,text="==>", bg="green",
command=lambda:bar1.move_bar(1))

# placing the buttons at suitable location on the canvas


button.place(x=300,y=580)

button2 = Button(canvas,text="<==",bg="green",
command=lambda:bar1.move_bar(0))
button2.place(x=260,y=580)

# calling the function for defining


# the dimensions of ball
ball_set()
root.mainloop()
# Driver code
if( name ==" main__"):
main()
Output:

Result:
Thus, the python program for Catching the ball game was implemented and verifiedsuccessfully.

You might also like