0% found this document useful (0 votes)
16 views65 pages

GE3171 - Python Lab ManuaL

Uploaded by

spranavk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views65 pages

GE3171 - Python Lab ManuaL

Uploaded by

spranavk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 65

MEENAKSHI RAMASWAMY

ENGINEERING COLLEGE
Approved by AICTE New Delhi | Affiliated to Anna University
Trichy Main Road, Thathanur – 621804

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

GE3171 – PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY

I SEMESTER – R 2021

LABORATORY MANUAL

Prepared By: Approved By:


M.Makuru M.E., M.Makuru M.E.,
Assistant Professor, Asst.Professor &Head,
.
.

S. NO. NAME OF THE PROGRAM


Identification and solving of simple real life or scientific or technical
1
problems developing flow chart for the same.
1.1 Electricity Billing
1.2 Python program for sin series
1.3 Weight of a Motor Bike
1.4 Weight of a Steel Bar
1.5 Electrical Current in Three Phase AC Circuit
2 Python programming using simple statements and expressions
2.1 Exchanging the values of two variables in python
2.2 Circulate the values of n variables
2.3 Distance between two points
3 Scientific problems using Conditionals and Iterative loops.
3.1 Number Series-Fibonacci Series
3.2 Number Series - Odd Numbers
3.3 Number Pattern
3.4 Pyramid Pattern
4 Implementing real-time/technical applications using Lists & tuples
4.1. Basic operations of List
4.2. Library functions using list.
4.3 Components of car using list
4.4 Material required for construction of a building using list.
4.5 Library functions using tuples
4.6 Components of a car using tuples.
4.7 Construction of a materials
Implementing real-time/technical applications using Sets,
5.
Dictionaries.
5.1 Languages using dictionaries
5.2 Components of Automobile using dictionaries
5.3 Elements of a civil structure

.
6 Implementing programs using Functions.
6.1 GCD of given numbers using Euclid's Algorithm.
6.2 Square root of a given number using newtons method.
6.3 Factorial of a number using functions
6.4 largest number in a list
6.5 Area of shapes
7 Implementing programs using Strings.
7.1 Reverse of a string
7.2 Palindrome of a string
7.3 Character count of a string
7.4 Replace of a string
Implementing programs using written modules and Python
8
Standard Libraries.
8.1 Convert list in to a Series using pandas
8.2 Finding the elements of a given array is zero using numpy
8.3 Generate a simple graph using matplotlib
8.4 Solve trigonometric problems using scipy
9 Implementing real-time/technical applications using File handling.
9.1 Copy text from one file to another
9.2 Command Line Arguments(Word Count)
9.3 Find the longest word(File handling)
Implementing real-time/technical applications using Exception
10
handling.
10.1 Divide by zero error – Exception Handing
10.2 Voter’s age validity
10.3 Student mark range validation
11 Exploring Pygame tool.
12 Developing a game activity using Pygame
12.1 Simulate Bouncing Ball Using Pygame
12.2 Simulate Car race Using Pygame

.
Ex : 1.1
Electricity Billing
Date:

Aim:
To write a python program to print electricity bill.

Algorithm:

Step 1: Start theprogram


Step 2: Read the current reading in cr and previous reading in
Step 3: Calculate total consumed by subtracting cr withpr
Step 4: if total consumed is between 0 and 101, print amount to pay is consumed * 2
Step 5: if total consumed is between 100 and 201, print amount to pay is consumed * 3
Step 6: if total consumed is between 200 and 501, print amount to pay is consumed * 4
Step 7: if total consumed is greater than 500, print amount to pay is consumed *5
Step 8: if total consumed is less than one print invalid reading
Step 9: Stop

.
Flow chart:

Result .
: Thus the python program for generating electricity bill is executed and the
results

.
are verified

.
Ex : 1.2
Python program for sin series
Date:

Aim:

To write a python program for sin series.

Algorithm:

Step 1: Start
Step 2: Read the values of x and
n Step 3: Initialize sine=0
Step 4: Define a sine function using for loop, first convert degrees to radians.
Step 5: Compute using sine formula expansion and add each term to the sum
variable. Step 6: Print the final sum of the expansion.
Step 7: Stop.

.
Flow Chart:

.
Result:
.

Thus the python program for sin series is executed and the results are verified
Ex : 1.3
Weight of a Motor Bike
Date:

Aim:
To write a python program to calculate the weight of a motor bike.

Algorithm:
Step 1: Start the program
Step 2: Read the value of a mass
Step 3: Calculate the weight of a motor bike by multiplying mass with 9.8 and store it in weight
Step 4: Print the weight
Step 5: Stop

Flow chart:

Start

Enter the value M


(mass) Of Motorbike

Initialize g(gravity)=9.8

Compute W=m*g

Value
Print the valWeight

Stop

.
Result .
:
Thus the python program to calculate the weight of a motor bike is executed and
the results are verified.
Ex : 1.4
Weight of a Steel Bar
Date:

Aim:
To write a python program to calculate the weight of a steel bar.

Algorithm:
Step 1: Start the program
Step 2: Read the value of a diameter and length
Step 3: Calculate the weight of a steel bar by using the formula of
((diameter*diameter)/162.28)*length and store it in weight.
Step 4: Print weight
Step 5: Stop

Flow chart:

Start

Enter the value M


(mass) Of Motorbike

Initialize g(gravity)=9.8

Compute W=m*g

Print the Weight

Stop
.
Result:
Thus the python program to calculate the Weight of a steel bar is executed and the
results are verified.
Ex : 1.5
Electrical Current in Three Phase AC Circuit
Date:

Aim:
To write a python program to calculate the electrical current in Three Phase AC Circuit.

Algorithm:

Step 1: Start the program.


Step 2: Read all the values of resistance, frequency and voltage.
Step 3: Calculate the electrical current in three phases AC Circuit.
Step 4: Print the result.
Step 5: Stop

Flow Chart:

Start

Initalize the valuesfor


R,X_L,V_L,f

Compute
V_Ph=V_L/1.732 # in V Z_Ph=sqrt((R**2)+(X_L**2))# in ohm I_Ph=V_Ph/Z_Ph# in A
I_L=I_Ph# in A

Print the kW

Stop
.
Result .
: Thus the python program to calculate the electrical current in Three Phase AC
Circuit is executed and the results are verified.
Ex : 2 (a)
Exchanging the values of two variables in python
Date:

Aim:

To write a python program to Exchanging the values of two variables taking input from the user.

Algorithm:

Step 1 : Start
Step 2 : Define a function named format()
Step 2 : Read the input values X and Y
Step 3 : Perform the followingsteps
Step 3.1 : temp = x
Step 3.2 : x = y
Step 3.3 : y =temp
Step 4 : Print the swapped value as result
Step 5 : End
Resul
t .

Thus the Python program to exchange the values of two variables was executed successfully
and the output is verified.
Ex : 2 (b)
Circulate the values of n variables
Date:

Aim:

Write a python program to Circulate the values of n variables taking input from the user

Algorithm:

Step 1: Start
Step 2: Declare a list
Step 3: Read number of input value.
Step 4: Store the value of input in list.
Step 5: Print the original list.
Step 6: Use range function with for loop to circulate the values
Step 7: Print the result.

Result
Thus, the Python program to Circulate th.e values of n variables was executed
successfully and the output is verified.
Ex : 2 (c)
Distance between two points
Date:

Aim:
Write a python program to calculate distance between two points taking input from the user.

Algorithm:

Step 1: Start
Step 2: Define a functionmath.sqrt ()
Step 3: Read the value of coordinates of two points P1 and
P2 Step 4: Perform the following step
Step 5: dist = math.sqrt( ((x2-x1)**2) + ((y2-y1)**2)
) Step 6: Print the distance between two points
Step 7: End

.
Resul
t
Thus, the Python program to calculate distance between two points was executed successfully
and the output is verified.
Ex : 3 (a)
Number Series-Fibonacci Series
Date:

Aim:
To Write a python program to print Fibonacci series taking input from the user
Algorithm:

Step 1 : Start
Step 2 :Read the input values using input()
Step 3 : Assign f1= -1 and f2=1.
Step 4 : Perform the term = f1+f2
Step 5 : Print the value as result
Step 6 : Perform the following
swap Step 7 : step f1 = f2
Step 8 : f2 = term
Step 9 : End

:501123

Result .
Thus, the Python program to print Fibonacci series was executed successfully and the
output is verified.
Ex : 3 (b)
Number Series - Odd Numbers
Date:

Aim:
To write a python program to print odd numbers by taking input from the user
Algorithm:

Step 1: start
Step 2: Declare the list of numbers using list.
Step 3: Use for loop to iterate the numbers in list.
Step 4: Check for condition
Step 5: Num % 2==0
Step 6: Print the result.
Step 7: End

Result .

Thus, the Python program to print odd numbers was executed successfully and the
output is verified.
Ex : 3 (c)
Number Pattern
Date:

Aim:
To write a python program to print numbers patterns.

Algorithn:

Step 1: Start the program.


Step 2: Declare the value for rows.
Step 3: Let i and j be an integer number.
Step 4: Repeat step 5 to 8 until all value parsed
Step 5: Set i in outer loop using range function, i = rows+1 and rows will be initialized to i
Step 6: Set j in inner loop using range function and i integer will be initialized to j
Step 7: Print i until the condition becomes false in inner loop.
Step 8: Print new line until the condition becomes false in outer loop.
Step 9: Stop the program.

Result:
Thus the python program to print numbers patterns is executed and verified.
Ex : 3 (d)
Pyramid Pattern
Date:

Aim:
To write a python program to print pyramid patterns

Algorithm:

Step 1: Start theprogram.


Step 2: Read the input values using input()
Step 3: Perform the following. m = (2 * n) –2
Step 4: Decrementing m after each loop Perform the
following. Step 5: m=m–1
Step 6: Print full Triangle pyramid using stars.
Step 7: Print the value until the for loop ends.
Step 8: Step 9: Stop theprogram.

Resul
t
Thus, the Python program to print Pyramid Pattern was executed successfully and the output
is verified.

.
Ex : 4.1
Implementing real-time/technical applications using Lists
Date: Basic operations of List

Aim:

To write python programs using list functions to perform the operations of list library.
Algorithm:

Step 1: Start
Step 2: Declare alist
Step 3: Read the input value.
Step 4: Store the value of input inlist.
Step 5: Process the list functions present in library function.
Step 6: Print theresult
Step 7: End

.
Result
Thus, the Python using list functions present in list library was executed successfully and the
Output verified.

.
Ex : 4.2
Library functionality using list.
Date:

Aim:
To write a python program to implement the library functionality using list.

Algorithm:
Step1: Start the program
Step2: Initialize the book list
Step 3: Get option from the user for accessing the libraryfunction
3.1. Add the book tolist
3.2. Issue abook
3.3. Return thebook
3.4. View the list ofbook
Step 4: if choice is 1 then get book name and add to booklist
Step 5: if choice is 2 then issue the book and remove from book list
Step6 : if choice is 3 then return the book and add the book to list
Step 7: if choice is 4 then the display the booklist
Step8: otherwise exit from menu
Step9: Stop theprogram.

Result:
Thus the python program to implement the library functionality using list is executed and
Results are verified.

.
results are verified
Ex : 4.3
Date: Components of car using list

Aim:
To write a python program to implement the operation of list for components of car.

Algorithm:

Step 1: Start the program.


Step 2: Create a list of components for car
Step 3: Get single component from user and append into list
Step 4: Find the length of the list using len function
Step 5: Find the minimum and maximum value of the list
Step 6: Print the component using index of the list
Step 7: Multiply the list element using multiplication operation
Step 8: Check the component exist in the list or not using in operator
Step 9: Stop the program.

.
Result
Thus the python program to create a list for components of car and performed the

.
Ex : 4.4
Material required for construction of a building using list.
Date:

Aim:
To write a python program to create a list for materials requirement of construction and perform
the operation on the list.

Algorithm:
Step 1: Start theprogram.
Step 2: Create a list of construction material.
Step 3: Sort the list using sortfunction.
Step 4: Printcc.
Step 5: Reverse the list using reverse function.
Step 6: Print cc.
Step 7: Insert y value by using index position.
Step 8: Slice the values using del function with start value and end up value.
Step 9: Print thecc
Step 10: Print the position of the value by using indexfunction.
Step 11: Print the values in the list of the letter ‘n’ by using for loop and member ship
operator.
Step 12: Stop theprogram.

Result:
Thus the python program to create a list for construction of a building using list is executed
Ex : 4.5
Library functions using tuples
Date:

Aim:
To write a python program to implement the library functionality using tuples.

Algorithm
Step 1: Start theprogram
Step 2: Create a tuple named asbook.
Step 3: Add a “NW” to a book tuple by using + operator.
Step 4: Print book.
Step 5: Slicing operations is applied to book tuple of the range 1:2 and printbook.
Step 6: Print maximum value in thetuple.
Step 7: Print maximum value in thetuple.
Step 8: Convert the tuple to a list by using list function.
Step 9: Delete thetuple.
Step 10: Stop theprogram.

Result:
Thus the python program to implement the library functionality using tuple is
executed and the results are verified .
Ex : 4.6
Components of a car using tuples.
Date:

Aim:
To write a python program to implement the components of a car using tuples.

Algorithm:
Step 1: Start theprogram
Step 2: Create a tuple named ascc
Step 3: Adding a value to a tuple is by converting tuple to a list and then assign “ Gear”value
to y[1] and convert it to atuple.
Step 4: Step 3is implemented for removing a value intuple.
Step 5: Type function is used to check whether it is list or tuples.
Step 6: Stop theprogram.

Result:
Thus the python program to implement components of a car using tuples is

executed and verified. .


Ex : 4.7
Construction of a materials
Date:

Aim:
To write a python program to implement the construction of a materials using tuples.

Algorithm:

Step 1: Start theprogram


Step 2: Create a tuple named ascm
Step 3: tuple unpacking method is applied and print values.
Step 4: count the elements in the tuple using count function.
Step 5: Index function is used to get the position of an element.
Step 6: Convert the string to a tuple and printvariable.
Step 7: Sort the values of a tuple to list using sorted function.
Step 8: Print the type function forsorted.
Step 9: Stop theprogram.

.
Result:
Thus the python program to create a tuple for materials of construction and
performed the various operations and result is verified.

.
Ex : 5.1 Implementing real-time/technical applications using Sets,
Date: Dictionaries.
Languages using dictionaries

Aim:
To write a python program to implement the languages using dictionaries.

Algorithm:
Step1: Start theprogram
Step 2: Create a empty dictionary using{}
Step 3: dict() is used to create adictionary.
Step 4: To add a value, update() is used in key value pair.
Step 5: Calculate the total values in the dictionary using len().
Step 6: Remove the particular key in the dictionary by using pop()
Step 7: Print the keys in the dictionary by usingkey()
Step 8: Print the values in the dictionary by using values()
Step 9: Print the key value pair in the dictionary using items()
Step 10: Clear the the key value pair by usingclear()
Step 11: Delete the dictionary by using del dictionary

Result:
Thus the python program to implement languages using dictionaries is executed
and verified.

.
.
Ex : 5.2
Components of Automobile using dictionaries
Date:

Aim:
To write a python program to implement automobile using dictionaries.

Algorithm:
Step 1: Start the program
Step 2: Create a empty dictionary using {}
Step 3: dict() is used to create a dictionary.
Step 4: Get the value in the dictionary using get()
Step 5: adding [key] with value to a dictionary using indexing operation.
Step 6: Remove a key value pair in dictionary using popitem().
Step 7: To check whether key is available in dictionary by using membership operator in.
Step 8: Stop the program.

Result:
Thus the python program to implement automobile using dictionaries is executed

and verified. .
Ex : 5.3
Elements of a civil structure
Date:

Aim:

To write a python program to implement elements of a civil structure using dictionaries.


Algorithm:

Step 1: Start the program


Step 2: Create a empty dictionary using {}
Step 3: Create a dictionary using dict().
Step 4: To access the value in the dictionary indexing is applied.
Step 5: adding [key] with value to a dictionary using indexing operation..
Step 6: A copy of original dictionary is used by copy ().
Step 7: The length of the dictionary is by len().
Step 8: Print the values of the dictionary by using for loop
Step 9: Stop the program

dictionaries is executed and verified. .


Result:
Thus the python program to implement elements of a civil structure using

dictionaries is executed and verified. .


Ex : 6.1
GCD of given numbers using Euclid's Algorithm.
Date:

Aim:
To write a python program to find gcd of given numbers using Euclids algorithm.

Algorithm:

Step 1: Start the program.


Step 2: Read the values of a and b as positive integers in function call gcd(a,b).
Step 3: recursively function call gcd(a,b) will be computed in (b, a % b) if b!=0.
Step 4: if b is equal to 0 return a.
Step 5: Print the result.
Step 6: Stop the program.

Result:
Thus the python program to find gcd of given num.bers using Euclid’s method is executed and the
results are verified.
Ex : 6.2
Square root of a given number using newtons method.
Date:

Aim:
To write a python program to find to find square root of a given number using newtons method.

Algorithm:

Step 1: Start the program.


Step 2: Read the value of n, n being a positive integer in the function newtonSqrt(n)
Step 3: Let approx = 0.5 * n
Step 4: Let better = 0.5 * (apporx + n/approx)
Step 5: Repeat the following steps until better equals to approx
Step 5.1: Let approx = better
Step 5.2: Let better = 0.5 * (apporx + n/approx)
Step 6: Return the value approx as the square root of the given number n
Step 7: Print the result.
Step 8: Stop the program.

the results are verified. .


Result:
Thus the python program to find square root of given number using newtons method is executed and

the results are verified. .


Ex : 6.3
Factorial of a number using functions
Date:

Aim:
To write a python program to find the factorial of a given number by using functions.

Algorithm:

Step 1: Start the program.


Step 2: Read the value of n as positive integers in function call factorial(n).
Step 3: if n is not equal to zero, recursively function call factorial will be computed as n*
factorial(n-1) and return the value of n.
Step 4: if n is equal to 0, return the value as 1
Step 5: Print the result.
Step 6: Stop the program.

Result:
Thus the python program to find the factorial of a given number by using

functions is executed and the results are verified. .


Ex : 6.4
largest number in a list using functions
Date:

Aim:
To write a python program to find the largest number in the list.

Algorithm:
Step 1: Start the program.
Step 2: Read the limit of the list as n.
Step 3: Read n elements into the list.
Step 4: Let large =list[0]
Step 5: Execute for loop i= 1 to n and repeat the following steps for the value of n until the
condition becomesfalse.
Step 5.1: if next element of the list > large then
Step 5.1.1: large = element of the list
Step 6: Print the large value.
Step 7: Stop the program.

.
is executed and the results are verified.
Result:
Thus the python program to find the largest number in the list by using functions

.
is executed and the results are verified.
Ex : 6.5
Area of shapes
Date:

Aim:
To write a python program for area of shape using functions.

Algorithm:

Step 1: Start the program.


Step 2: Read the value of l and b as positive integers in function call rect(l,b).
Step 3: Recursively call function(rect) will be computed as x*y and return the result to the
function call rect(l,b).
Step 4: Print area of the rectangle.
Step 5: Read the value of num as positive integers in function call circle(num).
Step 6: Recursively call the function circle) will be computed as PI*(r*r) and return the
result to the function call circle(num).
Step 7: Print area of the circle.
Step 8: Read the values in function call triangle as a parameters.
Step 9: Recursively call(triangle) will be computed with a,b,c as a parameter and print the result.
Step 10: Read the values as positive integers in function call parallelogram(base,height).
Step 11: Recursively call(parallelogram) will be computed as a*b and return the result to the
function call parallelogram(Base, Height).
Step 12: Print area of
parallelogram.
Step 13: Stop the program.

.
Result:
Thus the python program for area of shape using functions is executed and the
results are verified

.
Ex : 7.1
Date: Reverse of a string

Aim:
To write a python program for reversing a string..
Algorithm:
Step 1: Start the program.
Step 2: Read the value of a string value by using function call reversed_string .
Step 3: if len(text)==1 return text.
Step 4: else return
reversed_string(text[1:])+text[:1].
Step 5: Print a
Step 6: Stop the program

Result:

Thus the python program for reversing a .string is executed and the results
verified. are
Ex : 7.2
Palindrome of a string
Date:

Aim:
To write a python program for palindrome of a string.
Algorithm:
Step 1: Start the program.
Step 2: Read the value of a string value by using input method.
Step 3: if string==string[::-1], print “ the string is palindrome ”.
Step 4: else print “ Not a palindrome ”.
Step 5: Stop the program

Result:
Thus the python program for palindrome of a string is executed and the results

are verified. .
Ex : 7.3
Character count of a string
Date:

Aim:
To write a python program for counting the characters of string.

Algorithm:

Step 1: Start the program.


Step 2: Define a string.
Step 2: Define and initialize a variable count to 0.
Step 3: Iterate through the string till the end and for each character except spaces, increment
the count by 1.
Step 4: To avoid counting the spaces check the condition i.e. string[i] != ' '.
Step 5: Stop the program.

Result: Thus the python program for counting the characters of string is executed and the results are

verified.
.
Ex : 7.4
Replace of a string
Date:

Aim:
To write a python program for replacing the characters of a string.

Algorithm:

Step 1: Start the program.


Step 2: Define a string.
Step 3: Determine the character 'ch' through which specific character need to be replaced.
Step 4: Use replace function to replace specific character with 'ch' character.
Step 5: Stop the program.

Result:
Thus the python program for replacing the given characters of string is executed
and the results are verified.

60
Ex : 8.1
Convert list in to a Series using pandas
Date:

Aim:
To write a python program for converting list in to a Series.

Algorithm:

Step 1: Start the program.


Step 2: import pandas library
Step 3: Create a object as pd for pandas.
Step 4: Define a list
Step 4: Convert the list into series by calling the series function
Step 4: print the result
Step 5: Stop the program.

Result:
Thus the python program for converting list in to a series is executed
and the results are verified.

61
Ex : 8.2
Finding the elements of a given array is zero using numpy
Date:

Aim:
To write a python program for testing whether none of the elements of a given array is zero.

Algorithm:

Step 1: Start the program.


Step 2: import numpylibrary
Step 3: Create a object as np for numpylibrary
Step 4: Define and initialize anarray
Step 5: to test if none of the elements of the said array is zero use all function
Step 6: print theresult
Step7: Stop theprogram.

Result:
Thus the python program for testing whether none of the elements of a given array is zero is
executed and the results are verified.

62
Ex : 8.3
Generate a simple graph using matplotlib
Date:

Aim:
To write a python program for generating a simple graph using matplotlib.
Algorithm:

Step 1: Start the program.


Step 2: from matplotlib import pyplotlibaray
Step 3: Create a object as plt for pyplot
Step 4: Use plot function to plot the given values
Step 5: Plot the result using show function
Step 6: Stop the program.

Result:
Thus the python program for generating a simple graph using matplotlib zero is executed
and the results are verified.

63
Ex : 8.4
Solve trigonometric problems using scipy
Date:

Aim:
To write a python program for finding the exponents and solve trigonometric problems using
scipy.

Algorithm:

Step 1: Start the program.


Step 2: from scipylibaray import special function
Step 3: Use exponent,sin,cos functions to perform scientific calculatins
Step 5: Plot the result.
Step 6: Stop the program.

Result:
Thus the python program for finding the exponents and solve trigonometric problems using
scipy is executed and the results are verified.

64
Ex : 9.1
Copy text from one file to another
Date:

Aim:
To write a Python program for copying text from one file to another.
Algorithm:

Step 1 : Start
Step 2 : Create file named file.txt and write some data into it.
Step 3 : Create a file name sample.txt to copy the contents of the file
Step 4 : The file file.txt is opened using the open() function using the f stream.
Step 5 : Another file sample.txt is opened using the open() function in the write mode using the
f1 stream.
Step 6 : Each line in the file is iterated over using a for loop (in the input stream).
Step 7 : Each of the iterated lines is written into the output file.
Step 8 : Stop

Result:
Thus the python program for copying text from one file to another is executed and the results
are verified.

65
Ex : 9.2
Command Line Arguments(Word Count)
Date:

Aim:
To write a Python program for command line arguments.

Algorithm:

Step1: Start
Step2: Import the package sys
Step3: Get the arguments in command line prompt
Step4: Print the number of arguments in the command line by using len(sys.argv) function
Step5: Print the arguments using str(sys.argv ) function
Step6: Stop

Result:
Thus the Python program for command line arguments is executed successfully and the
output is verified.

66
Ex : 9.3
Find the longest word(File handling)
Date:

Aim:
To write a Python program for finding the longest words using file handling concepts.

Algorithm:

Step1: Start the program


Step2: Create a text file name it file.txt and save it.
Step3: Open the text file in read mode
Step4: Read the file and split the words in the file separately.
Step4: Find the word with maximum length
Step5: Print the result.
Step6: Stop the program.

Result:
Thus the Python program finding the longest words using file handling concepts is executed
successfully and the output is verified.

67
Ex : 10.1
Date: Divide by zero error – Exception Handing

Aim:
To write a Python program for finding divide by zero error.

Algorithm:

Step1: Start the program


Step2: Take inputs from the user, two numbers.
Step 3: If the entered data is not integer, throw an exception.
Step 4: If the remainder is 0, throw divide by zero exception.
Step 5: If no exception is there, return the result.
Step6: Stop the program.

Result:
Thus the Python program for finding divide by zero error is executed successfully and the
output is verified.

68
Ex : 10.2
Date: Voter’s age validity

Aim:
To write a Python program for validating voter’s age.
Algorithm:

Step1: Start the program


Step 2: Accept the age of the person.
Step 3: If age is greater than or equal to 18, then display 'You are eligible to vote'.
Step 4: If age is less than 18, then display 'You are not eligible to vote'.
Step 5: If the entered data is not integer, throw an exception value error.
Step 6: : If the entered data is not proper, throw an IOError exception
Step 7: If no exception is there, return the result.
Step 8: Stop the program.

69
Result:
Thus the Python program for validating voter’s age is executed successfully and the output is
verified.

70
Ex : 10.2
Student mark range validation
Date:

Aim:
To write a python program for student mark range validation

Algorithm:

Step 1: Start the program


Step 2: Get the inputs from the users.
Step 3: If the entered data is not integer, throw an exception.
Step 4: If no exception is there, return the result.
Step 5: Stop the program.

71
Result:
Thus the python program for student mark range validation is executed and verified.

72
Ex : 11
Exploring Pygame tool.
Date:

Pygame:

Pygame is a set of Python modules designed to make games. It uses SDL


(Simple Direct Media Layer) which is a cross-platform library that abstracts the
multimedia components of a computer as audio and video and allows an easier
development of programs that uses these resources.

Steps for installing pygame package:

1. Open Windows command prompt by typing cmd in startupmenu


2. C:\Users\admin>cd..
3. C:\Users>cd..
4. C:\>cd Portable Python3.2.5.1
5. C:\Portable Python 3.2.5.1>py -m pip install -U pygame–user

Result:
Thus the Python program for validating voter’s age is executed successfully and the output is
verified.

73
Ex : 11.1
Simulate Bouncing Ball Using Pygame
Date:

Aim:
To write a Python program to simulate bouncing ball in pygame.

Algorithm:

Step1: Start

Step2: Import the necessary packages

Step3: Initialize the height, width and speed in which the ball bounce

Step4:Set the screen mode

Step5: Load the ball image

Step4: Move the ball from left to right

Step5: Stop

Result:

Thus the Python program to simulate bouncing ball using pygame is executed successfully
and the output is verified.

74
Ex : 11.2
car race
Date:

Aim:
To write a Python program to simulate car race in pygame.

Algorithm:

Step1: Start

Step2: Import the necessary packages

Step3: Initialize the height, width and speed in which the ball bounce

Step4:Set the screen mode

Step5: Load the ball image

Step4: Move the ball from left to right

Step5: Stop

Result:

Thus the Python program to simulate car race using pygame is executed successfully and the
output is verified.

75

You might also like