0% found this document useful (0 votes)
7 views91 pages

231ges114l-Pspp Lab Manual-2023r (Students)

The document is a laboratory manual for the Problem Solving through Python Programming course at Easwari Engineering College, detailing a list of experiments and course outcomes for first-year IT students. It covers various programming tasks such as flowchart development, Python programming basics, data structures, file handling, exception handling, and game development using Pygame. The manual also includes installation procedures for Python and an introduction to its features and modes.
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)
7 views91 pages

231ges114l-Pspp Lab Manual-2023r (Students)

The document is a laboratory manual for the Problem Solving through Python Programming course at Easwari Engineering College, detailing a list of experiments and course outcomes for first-year IT students. It covers various programming tasks such as flowchart development, Python programming basics, data structures, file handling, exception handling, and game development using Pygame. The manual also includes installation procedures for Python and an introduction to its features and modes.
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/ 91

EASWARI ENGINEERING

COLLEGE

DEPARTMENT OF INFORMATION TECHNOLOGY

231GES114L-PROBLEM
SOLVING THROUGH PYTHON
PROGRAMMING
LABORATORY

LAB MANUAL
(Student Copy)

I YEAR IT

SEP 2024 to JAN 2025


PROBLEM SOLVING THROUGH PYTHON Periods per week
231GES114L Credits
PROGRAMMING LABORATORY L T P R
0 0 3 1 2

LIST OF EXPERIMENTS
1. Identification and solving of simple real life or scientific or technical problems, and developing
flow charts for the same. (Electricity Billing, Retail shop billing, Sin series, weight of a
motorbike, Weight of a steel bar, compute Electrical Current in Three Phase AC Circuit, etc.)
2. Python programming using simple statements and expressions (exchange the values of two
variables, circulate the values of n variables, distance between two points).
3. Scientific problems using Conditionals and Iterative loops. (Number series, Number Patterns,
pyramid pattern)
4. Implementing real-time/technical applications using Lists, Tuples. (Items present in a
library/Components of a car/ Materials required for construction of a building –operations of list
& tuples)
5. Implementing real-time/technical applications using Sets, Dictionaries. (Language, components
of an automobile, Elements of a civil structure, etc.- operations of Sets & Dictionaries)
6. Implementing programs using Functions. (Factorial, largest number in a list, area of shape)

7. Implementing programs using Strings. (reverse, palindrome, character count, replacing


characters)
8. Implementing programs using written modules and Python Standard Libraries (pandas, numpy.
Matplotlib, spicy)
9. Implementing real-time/technical applications using File handling. (copy from one file to another,
word count, longest word)
10. Implementing real-time/technical applications using Exception handling. (divide by zero error,
voter’s age validity, student mark range validation)
11. Exploring Pygame tool.

12. Developing a game activity using Pygame like bouncing ball, car race etc.

13. Mini Project

60 PERIODS

COURSE OUTCOMES:
Upon completion of this course, student will be able to:
CO1: Develop algorithmic solutions to simple computational problems
CO2: Implement programs in Python using conditionals and loops for solving problems
CO3: Deploy functions to decompose a Python program
CO4: Process compound data using Python data structures.
CO5: Design Python programs for file handling and exception handling.
CO6: Create GUI application for user defined requirement.
Ex. No. DATE PROGRAM MARKS SIGNATURE
1.a Identification and solving of simple real
life and developing flow chart for the same
for Electricity Billing
1.b Identification and developing flow chart for
Retail shop billing
1.c Identification and developing flow chart for
Sin series
1.d Develop a flow chart for calculating the
weight of a motorbike / Weight of a steel bar
1.e Develop a flow chart to compute Electrical
Current in Three Phase AC Circuit
2.a Python programming using simple
statements and expressions - exchange the
values of two variables
2.b circulate the values of n variables

2.c Distance between two points

3.a Scientific problems using Conditionals and


Iterative loops – (Number series) Fibonacci
Series
3.b Number Patterns

3.c Pyramid patterns

4.a Implementing real-time applications using


Lists, Tuples - Items present in a library
4.b Components of a car – operations of list &
tuples
5.a Implementing real-time applications using
Sets, Dictionaries - components of an
automobile
5.b Implementing operations of Sets &
Dictionaries - Elements of a civil structure

6.a Implementing programs using Functions. -


Factorial

6.b Finding largest number in a list using


Functions
6.c Implementing programs using Functions -
To calculate the area of shape
7.a Implementing programs using Strings
–reversing a string
7.b To check whether a given string is
palindrome or not
7.c To determine the character count

7.d To replace character in a String

8.a Implementing programs using written


modules and Python Standard Libraries -
pandas
8.b Implementing programs using written
modules and Python Standard Libraries -
numpy
8.c Implementing programs using written
modules and Python Standard Libraries -
Matplotlib
8.d Implementing programs using written
modules and Python Standard Libraries -
scipy
9.a Implementing real-time applications using
File handling. – To copy the content from
one file to another
9.b To determine the word count in a given file

9.c To find the longest word in the given


content
10.a Implementing real-time applications using
Exception handling – To handle the divide
by zero error
10.b Implementation of voter’s age validity
using Exception handling
10.c Implementation of student mark range
validation using Exception handling
11. Exploring Pygame tool.

12.a Developing a game activity using Pygame -


bouncing ball
12.b Develop a car race game using Pygame
13. Mini project
INTRODUCTION TO PYTHON
AND INSTALLATION PROCEDURE

Python is a high-level, general-purpose, interpreted, interactive, object- oriented


dynamic programming language. It was created by Guido van Rossum during 1985- 1990.
Like Perl, Python source code is also available under the GNU General Public License
(GPL). Python is named after a TV Show called ‘Monty Python’s Flying Circus’ and not
after Python-the snake.
Python 3.0 was released in 2008. Although this version is supposed to be backward
incompatibles, later on many of its important features have been back ported to be
compatible with version 2.7
Installing Python
Virtually all modern programming languages make us of an IDE, or Integrated
Development Environment, which allows the creation, editing, testing, and saving of
programs and modules.
For Python programming you need a working Python installation and a text editor.
Python comes with its own editor, IDLE, which is quite nice and totally sufficient for the
beginning.
The Python download page is http://www.python.org/download. The most recent
version is Python 3.5.3 (as of January 2017);
Windows users
Download the appropriate Windows installer
Mac users
Starting from Mac OS X Tiger, Python ships by default with the operating system, but
you will need to update to Python 3 until OS X starts including Python 3 (check the version
by starting python3 in a command line terminal). Also IDLE (the Python editor) might be
missing in the standard installation. If you want to (re-)install Python, get the MacOS
installer from the Python download site.
Linux, BSD, and UNIX users
IDLE may need to be installed separately, from its own package such as idle3 or as
part of python-tools.
If you have to install Python, first try to use the operating system's package manager or go
to the repository where your packages are available and get Python
3. Python 3.0 was released in December 2008; all distributions should have Python 3
available, so you may not need to compile it from scratch. Ubuntu and Fedora do have
Python 3 binary packages available, but they are not yet the default, so they need to be
installed specially.
Roughly, here are the steps to compile Python from source code in Unix (If these
totally don't make sense, you may want to read another introduction to *nix, such as
Introduction to Linux):
Download the .tgz file (use your Web browser to get the
gzipped tarfile from
https://www.python.org/downloads/release/python-343)
Uncompress the tar file (put in the correct path to where you downloaded it):
Change to the directory and tell the computer to compile and install the program

Add Python 3 to your path. You can test it first by specifying the full path. You
should add $HOME/python3_install/bin to your PATH bash variable.
$ ~/python3_install/bin/python3
Python 3.4.3 (... size and date information ...)[GCC 4.5.2] on
linux2
Type "help", "copyright", "credits" or "license" for more
information. >>>

The above commands will install Python 3 to your home directory, which is probably
what you want, but if you skip the --prefix=$HOME/python3_install, it will install it to
/usr/local. If you want to use the IDLE graphical code editor, you need to make sure that the
tk and tcl libraries, together with their development files, are installed on the system. You will
get a warning during the make phase if these are not available.
Configuring your PATH environment variable
The PATH environment variable is a list of folders, separated by semicolons, in which
Windows will look for a program whenever you try to execute one by typing its name at a
Command Prompt. You can see the current value of your PATH by typing this command at a
Command Prompt:
The easiest way to permanently change environment variables is to bring up the
built-in environment variable editor in Windows. How you get to this editor is slightly
different on different versions of Windows.
On Windows 8 or Windows 10:
Press the Windows key and type Control Panel to locate the Windows Control Panel.
Once you've opened the Control Panel, select View by: Large Icons,
then click on System. In the window that pops up, click the Advanced System Settings link,
then click the Environment Variables... button.
On Windows 7 or Vista:
Click the Start button in the lower-left corner of the screen, move your mouse over
Computer, right-click, and select Properties from the pop-up menu. Click the Advanced
System Settings link, then click the Environment Variables... button.
On Windows XP:
Right-click the My Computer icon on your desktop and select Properties. Select the
Advanced tab, then click the Environment Variables... button.
Once you've brought up the environment variable editor, you'll do the same thing
regardless of which version of Windows you're running. Under System Variables in the

bottom half of the editor, find a variable called PATH. If there is is one, select it and click
Edit.... Assuming your Python root is C:\Python34, add these two folders to your path (and
make sure you get the semicolons right; there should be a semicolon between each folder in
the list):

Python programming – modes


Python has two basic modes: normal and interactive. The normal mode is the mode
where the scripted and finished .py files are run in the Python interpreter. Interactive mode is
a command line shell which gives immediate feedback for each statement, while running
previously fed statements in active memory. As new lines are fed into the interpreter, the fed
program is evaluated both in part and in whole.
Interactive mode is a good way to play around and try variations onsyntax. On
macOS or linux, open a terminal and simply type "python". On
Windows, bring up the command prompt and type "py", or start an interactive Python
session by selecting "Python (command line)", "IDLE", or similar program from the task
bar / app menu. IDLE is a GUI which includes both an interactive mode and options to edit
and run files. Python should print something like this:

>>>

The >>> is Python's way of telling you that you are in interactive mode. In interactive
modewhat you type is immediately run. Try typing 1+1 in. Python will respond with 2.
Interactive mode allows you to test out and see what Python will do. If you ever feel the
need to play with new Python statements, go into interactive mode and try them out. A
sample interactive session:

However, you need to be careful in the interactive environment to avoid confusion.


For example, the following is a valid Python script:

If you try to enter this as written in the interactive environment, you might be surprised

by the result:
What the interpreter is saying is that the indentation of the second print was
unexpected. You should have entered a blank line to end the first (i.e., "if") statement, before
you started writing the next print statement. For example, you should have entered the
statements as though they were written:
Which would have resulted in the following:

Interactive mode
Instead of Python exiting when the program is finished, you can use the - i flag
tostart an interactive session. This can be very useful for debugging and prototyping.
Exp:1(a) Identification and solving of simple real life or scientific or technical problems
Date: and developing flow chart for Electricity billing

AIM:
To construct an algorithm and flowchart for electricity bill in python.
ALGORITHM:
STEP 1: Start
STEP 2: nput unit consumed by customer
STEP 3: f unit consumed less or equal to 200 units. Then Total_charge = no.of.unit *
2.50
STEP4: f unit consumed more than 201 units but less than 500 units. Then add the first
200 units amounti.e. 2.50. Which is given by Total_charge=
(no.of.unit- 200)*3.50+(200*2.50).
STEP 5: f unit consumed more than 501units. Then add first two units 200 and
500units amount i.e. 2.50& 3.50. Which is given by Total_charge=
no.of.unit- 0)*5.00+(300*3.50)+(200*2.50).
STEP 6: Similarly check rest of the conditions and calculate total amount.
STEP 7: After calculating total amount print the statement in Total charge.

STEP 8: Stop.

FromUnit ToUnit Rate(Rs.) Max.Unit


1 100 0 100
101 200 2 200
201 500 3 500-
- 101-200 3.5 >500
201-500 4.6 >500
>500 606 >500
FLOWCHART

RESULT:
Thus the problem is identified and the solution is successfully given with a
flowchart.
Exp:1(b) Identification and solving of simple real life and
Date: developing flow chart for Retail Shop Billing

AIM:
To construct an algorithm and flowchart for retail shop billing in
python.
ALGORITHM:
STEP 1: Start.
STEP 2: Open the APP.
STEP 3: Initialize or select the packages/items.
STEP4: Add product details.(insert/delete/update).
STEP 5: Scan barcode.
STEP 6: Check shopping.
STEP 7: Calculate total, update database and give feedback.
STEP 8: Make payment .
STEP 9: Stop.
FLOWCHART:

RESULT:
Thus the problem is identified and the solution is successfully
given with a flowchart.
Exp:1(c) Identification and solving of simple scientific problems
Date: and developing flow chart for Sin series
AIM:
To construct an algorithm and flowchart for calculating sine series
in python.
ALGORITHM:
STEP 1:
STEP 2:
STEP 3:
STEP4:
STEP 5:
STEP 6:
STEP 7:
STEP 8:
FLOWCHART:

RESULT:
Thus the problem is identified and the solution is successfully
given with a flowchart.
Exp:1(d) Identification and solving of simple real life or
Date: scientific or technical problems and developing flow
charts for calculating weight of steel bar

AIM:
To construct an algorithm and flowchart for calculating weight of
a steel bar in python .

ALGORITHM:

FLOWCHART:
RESULT:
Thus the problem is identified and the solution is successfully
given with a flowchart.
Exp:1(e) Identification and solving of simple real life or
Date: scientific or technical problems and developing flow
charts for Calculating Electrical Current in Three
Phase Ac Circuit

AIM:
To construct an algorithm and flowchart for calculating electrical
current in three phase ac circuit in python

ALGORITHM:
FLOWCHART:

RESULT:
Thus the problem is identified and the solution is successfully
given with a flowchart.
Exp:2 (a) Python programming using simple statements and
expressions
EXCHANGE OF THE VALUES OF TWO VARIABLES
Date:

AIM:
To write a Python program to perform Swapping of two numbers.
ALGORITHM:
Step 1:Define a function swap and call the function. Step 2:Get the
first number
Step 3:Get the second number
Step 4:Print the numbers before swapping
Step 5:Assign the first number with temporary variable ‘temp’ Step
6:Store the second number to the first number
Step 7:Reassign the second number to the temporary variable Step
8:Print the Swapped values.
Step 9: Stop
PROGRAM: Method-1-without using another variable
x=5
y=7
print ("Before swapping: ")
print("Value of x : ", x, " and y : ", y)

# code to swap 'x' and 'y'


x, y = y, x

print ("After swapping: ")


print("Value of x : ", x, " and y : ", y)

Method-2- using third variable


x=5
y=7

#x = input('Enter value of x: ')


#y = input('Enter value of y: ')
# create a temporary variable and swap the values
temp = x
x=y
y = temp

print('The value of x after swapping: {}'.format(x))


print('The value of y after swapping: {}'.format(y))

Method-3- without using third variable


x=5
y=7

x=x+y
y=x-y
x=x-y

print ("After swapping: ")


print("Value of x : ", x, " and y : ", y)
OUTPUT:

RESULT:
Thus the Python programs to exchange the values between
two variables are executed successfully and the output is
verified.
Exp:2 (b) Python programming using simple statements and
Date: expressions
CIRCULATE THE VALUES OF N VARIABLES

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:2 (c) Python programming using simple statements and
Date: expressions
DISTANCE BETWEEN TWO POINTS

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:3 (a) SCIENTIFIC PROBLEMS USING CONDITIONALS AND
ITERATIVE LOOPS NUMBER SERIES
Date:
FIBONACCI SERIES

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:3 (b) SCIENTIFIC PROBLEMS USING CONDITIONALS AND
ITERATIVE LOOPS NUMBER SERIES
Date:
NUMBER PATTERN

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:3 (c) SCIENTIFIC PROBLEMS USING CONDITIONALS AND
ITERATIVE LOOPS NUMBER SERIES
Date:
PYRAMID PATTERN

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:4 (a) Implementing real-time/technical applications using Lists, Tuples
Date: Items present in a library - operations of List and Tuples

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:4 (b) Implementation of car component
Date: Operations of List and Tuples

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:4 (c) Implementing list on construction of a building
Date: Operations of List and Tuples

AIM:

ALGORITHM:

PROGRAM:
RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:5 (a) Implementing real-time/technical applications using Sets,
Date: Dictionaries.
Components of an automobile
Operations of Sets & Dictionaries

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:5 (b) Implementing real-time/technical applications using Sets,
Date: Dictionaries.
Implement Elements of a civil structure
Operations of Sets & Dictionaries

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:
RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:6 (a) Implementing programs using Functions
Date: FACTORIAL

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:6 (b) Implementing programs using Functions
Date: LARGEST OF TWO NUMBER IN A LIST

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:6 (c) Implementing programs using Functions
Date: AREA OF SHAPES

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:7 (a) Implementing programs using Strings
Date: REVERSE WORD IN STRING

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:7 (b) Implementing programs using Strings
Date: PALINDROME

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:7 (c) Implementing programs using Strings
Date: CHARACTER COUNT

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:7 (d) Implementing programs using Strings
Date: REPLACE A CHARACTER

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:8 (a) Implementing programs using written modules and Python
Date: Standard Libraries - Pandas

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:8 (b) Implementing programs using written modules and Python
Date: Standard Libraries - Numpy

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:8 (c) Implementing programs using written modules and Python
Date: Standard Libraries - Matplotlib

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:8 (d) Implementing programs using written modules and Python
Date: Standard Libraries - Scipy

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:9 (a) Implementing real-time/technical applications using File
Date: handling.
FILE COPYING

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:9 (b) Implementing real-time/technical applications using File
Date: handling.
WORD COUNT

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:9 (c) Implementing real-time/technical applications using File
Date: handling.
TO FIND THE LONGEST WORD IN THE GIVEN
CONTENT

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:10 (a) Implementation real time technical application using
Date: Exception Handling
DIVIDED BY ZERO ERROR

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:10 (b) Implementation real time technical application using
Date: Exception Handling
VOTER’S AGE VALIDATION

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:10 (c) Implementation real time technical application using
Date: Exception Handling
STUDENT MARK RANGE VALIDATION

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:11 EXPLORING PYGAME TOOL
Date:

AIM:

Write a python program to implement pygame Tool.


.

PROCEDURE:

1. Import and initialize the pygame library.


Without these lines, there is no pygame.
2. Sets up your program’s display window. You provide either a list or a tuple that
specifies the width and height of the window to create. This program uses a list to create a
square window with 500 pixels on each side.
3. Set up a game loop to control when the program ends. You’ll cover game loops later
on in this tutorial.
4. Scan and handle events within the game loop. You’ll get to events a bit later as well. In
this case, the only event handled is pygame.QUIT, which occurs when the user clicks the
window close button.
5. Fills the window with a solid color. screen.fill() accepts either a list or tuple
specifyingthe RGB values for the color. Since (255, 255, 255) was provided, the window is
filled with white.
6. Draws a circle in the window, using the following parameters:
7. screen: the window on which to draw
8.(0, 0, 255): a tuple containing RGB color values
9.(250, 250): a tuple specifying the center coordinates of the circle 10.75: the radius of the
circle to draw in pixels
11. Updates the contents of the display to the screen. Without this call, nothingappears in
the window!
12. exits pygame.
This only happens once the loop finishes.

PROGRAM:
# Simple pygame program

# Import and initialize the pygame library


import pygame
pygame.init()

# Set up the drawing window


screen = pygame.display.set_mode([500, 500])

# Run until the user asks to quit


running = True
while running:

# Did the user click the window close button?


for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

# Fill the background with white


screen.fill((255, 255, 255))

# Draw a solid blue circle in the center


pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)

# Flip the display


pygame.display.flip()

# Done! Time to quit.


pygame.quit()
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
12 (a) Developing a game activity using Pygame
Date: BOUNCING BALL

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.

Exp:12 (b) Developing a game activity using Pygame


Date: CAR RACE

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
Thus the program was executed and the output was verified
successfully.
Exp:13 MINI PROJECT
Date:

TITLE :

AIM:

ALGORITHM:

PROGRAM:
OUTPUT:

RESULT:
REPORT
SUBMITTED
ON:

COMPLETED
SIGNATURE:

You might also like