0% found this document useful (0 votes)
24 views22 pages

Satyam Pthon

The document is a laboratory manual for a Python Programming course in the Department of Mechanical Engineering, outlining the vision and mission of the department, course objectives, and outcomes for students. It includes a detailed list of experiments and practical applications of Python in various fields, as well as installation instructions for the programming environment. The manual aims to equip students with essential programming skills applicable to real-world engineering 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)
24 views22 pages

Satyam Pthon

The document is a laboratory manual for a Python Programming course in the Department of Mechanical Engineering, outlining the vision and mission of the department, course objectives, and outcomes for students. It includes a detailed list of experiments and practical applications of Python in various fields, as well as installation instructions for the programming environment. The manual aims to equip students with essential programming skills applicable to real-world engineering 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/ 22

DEPARTMENT OF MECHANICAL ENGINERING

Laboratory Manual

Python Programming
NAME: SATYAM GUPTA
ROLL NO: A 426
BATCH: SA-2
DEPARTMENT OF MECHANICAL ENGINEERING

2024-25
Vision
To be the department committed to nurture student cantered learning
experience through outcome and skill based transformative education to create
technocrats and leaders for the service of society and nation.

Python
Programming Lab
1
DEPARTMENT OF MECHANICAL ENGINERING
Mission
1. To provide an educational experience that transforms students into
competent Mechanical Engineering professionals and responsible
citizens.
2. To provide an academic ambiance in the department that flourish new
ideas, research interest, leadership, team spirit and ethics.
3. To strive for excellence in faculty and students of the department by
encouraging skills development, creativity, capability and applicability.
4. To join the institute in its contribution to the service of society by
participation of faculty, staff and students in socio-economic and
sociocultural activities.
5. To work on Research and Development projects and offer consultancies
in Mechanical Engineering and also in the interdisciplinary areas to
strengthen the education and research ecosystem.
6. To establish the linkages with apex educational and research institutions
at national level and support the institute to emerge into a Centre of
Excellence.

Python Programming
SE (Mechanical), Semester – IV
Course Objectives:

1. To introduce the basic concepts of Python programming language as


well as common packages and libraries.
2. To generate an ability to design, analyse and perform experiments on
real life problems in mechanical engineering using Python

Course Outcomes: Learner will be able to…

1. Demonstrate understand of basic concepts of Python Programming.


2. Identify, Install and utilize Python packages

Python
Programming Lab
2
DEPARTMENT OF MECHANICAL ENGINERING
3. Develop and execute Python program for specific applications
4. Develop and build Python program to solve real world engineering
problems.
5. Prepare a report on case studies selected Lab Outcomes:

1. Demonstrate understand of basic concepts of Python Programming.


2. Identify, Install and utilize Python packages
3. Develop and execute Python program for specific applications
4. Develop and build Python program to solve real world engineering
problems.
5. Prepare a report on case studies selected

Teaching Scheme and Credit Assigned


Teaching Scheme
Course Course Name Credit Assigned
(Contact Hours)
Code
Theory Practs Theory Practs Total

Python
MEL403 -- 02 -- 01 01
Programming

Mrs. Sowmyashree
Lab In charge

List of Experiments
Exp. Title of
Subtitles Page No.
No. Experiments

Python
Programming Lab
3
DEPARTMENT OF MECHANICAL ENGINERING
a) Introduction to Python and its applications
8-11

b) Installation of Python programming


environment: Installation of Latest Version of 12-16
Python on windows(python 3.9.1)
01 Introduction and
Installation of C) Installation of Python programming
Python environment: Installation of Anaconda 17-23
Navigator
Programs to a) To study Python Comments
25-26
understand
comments, b) To study Python Indentation 26
indentation,
02 identifiers, c) To study Python Identifiers
27
variables and
Input-Output d) To study Python Variables
Functions 28-29

e) To study Python Input output functions


30-33

Programs to a) To study Python Numbers


35-38
understand
Python Data types: b) To study Python Strings 38-44
03 Numbers, Strings,
Boolean c)
To study Python Boolean 45-46

Programs to a) To study python Lists : indexing, slicing, builtin


understand Python functions and methods 48-55
standard data
04 types: list, tuple and b) To study python Tuple: : indexing, slicing,
Dictionary builtin functions and methods 55-62

c) To study python Dictionary 62-66

Programs to study a) To study Python Operators 68-72


Operators, byte and
byte arrays and b) To study Python bytes () 72-73
05 Sets
c) To study Python byte arrays 74-75
d)
To study Python Sets 75-81

a) if statement
83-84

Python
Programming Lab
4
DEPARTMENT OF MECHANICAL ENGINERING
6 Programs to b) if …. else statement
84-85
understand

c) if..elif…else statement
85-86

Conditional d) Nested if… else statement


86-87
statements
e) Single Statement Suites
87-90

Program to a)
while loop 92-95
understand Loops
and Loop control b) For loop 95-98
statements c) range() function 98-99
d)
7 Nested Loops 100
e)
Loop control statement :break 101-102
f)
Loop control statement :continue 102-103
g)
Loop control statement :pass 103-104
Programs to a) A simple function
understand b) Pass by value
8 Functions in Python c) Pass by Reference
106-115
d) Default arguments
e) Keyword arguments
f) Lamba expressions
Programs to
understand Object Programs to understand Object oriented
oriented Programming (OOP) concepts: classes, objects
Programming a) and methods
9
(OOP) concepts: 117-125
classes, objects and
methods

Programs to a)
Program to understand file open/read/close
understand 127-132
different file functions
10
handling operations b)
Program to understand file
132-135
write/append/create/delete functions

Python
Programming Lab
5
DEPARTMENT OF MECHANICAL ENGINERING
Sample case studies 1. A case study on –solving Linear Differential
Equation of Newton’s Law of Cooling using 136-142
python programming

2 Simulation of Robotic arm 143-150

Experiment Number: 01
Name of Experiment: Introduction and Installation of
Python
Date of Performance: 13/01/2025
Date of Submission: 20/01/2025

Python
Programming Lab
6
DEPARTMENT OF MECHANICAL ENGINERING

Experiment no. 1
Introduction and Installation of python
Aim:

a) Introduction to Python and its applications

b) Installation of Python programming environment: Installation of Latest Version of


Python on windows (python 3.9.1)

c) Installation of Python programming environment: Installation of Anaconda Navigator

a) Introduction to Python and its applications Theory:


What is Python?

Python is a general purpose programming language which can be used for almost anything
may it to be develop webpages or for machine learning or any sort of simple application.

History of Python:

In 1980’s Guido Van Rossum wanted to make a language that is beautiful to look at and easy
for everybody to read. As a hobby he started to make a language which uses indentations
instead of braces, as a result code becomes readable and named flying circus creator “Monty
python” it Python his favourite show. Created in 1989 and Released In 1991. Gaining
popularity for ML and AI as python makes code easy and efficient
Formally, Python is High level interpreted language which has easy syntax and dynamic
semantics

• High level: python derives components from natural language humans use to
communicate with each other
• Interpreted: python code is compiled line by line which makes debugging errors
much more easier and efficient ( but much more slower than other programming
languages)
• Dynamic semantics: do not have to initialize anything. It happens automatically
during runtime.

Python
Programming Lab
7
DEPARTMENT OF MECHANICAL ENGINERING
Features of Python

• Simplicity: It makes programming fun. You think more of obtaining solution to


problem rather than thinking about syntax of your code.
• Open source language: It is free for anybody to use. U can also modify python
to add next level features
• Supports portability: u can write and share it with your team or anybody it
would run the same way as it does for you. (Helpful when you are working on
an application with team of people.
• Embeddable and extensible: there may be chances that certain languages
perform certain functions better than python. Python allows you to add the
codes of those particular languages within itself which makes python more
powerful.
• Interpretation: Python is interpreted line by line, which means management
of memory and CPU is much more efficient and easy. A whole program may
take a lot of memory but python would take away the block of code which is
already been executed. This frees up memory and makes code run much
better.
• Huge library support: helps to obtain solutions to problems easily n efficiently.
• Object oriented (OOPS): you can model a real world problem into your code
and u can have security to that such that certain features only access those
particular data elements. This can helps you in replicating real world
problems.

Who uses Python?

1000’s of companies’ uses python for daily business requirements. Few


examples:
• Google uses python to provide better search features to its users.
• Dropbox server and client applications have been coded using python
• National security agency uses python for cyber security analysis and
encryption and decryption purposes.
• Bittorrent uses python to share files between the users.
• Raspberry Pi is a credit size computer which promotes python as its
educational language.
• NASA: scientists use python for scientific calculations
• Netflix uses python to understand and cluster certain groups of users and
recommend them TV shows.ML
• YouTube: to provide better searches to its users

Python
Programming Lab
8
DEPARTMENT OF MECHANICAL ENGINERING
Applications of Python Programming:

Python supports cross-platform operating systems which makes building applications


with it all the more convenient. Some of the globally known applications such as YouTube,
BitTorrent, DropBox, etc. use Python to achieve their functionality.
1. Web Development
Python can be used to make web-applications at a rapid rate. Why is that? It is because of the
frameworks Python uses to create these applications. There is common-backend logic that
goes into making these frameworks and a number of libraries that can help integrate
protocols such as HTTPS, FTP, SSL etc. and even help in the processing of JSON, XML, E-Mail
and so much more.

2. Game Development

Python is also used in the development of interactive games. There are libraries such as
PySoy which is a 3D game engine supporting Python 3, PyGame which provides functionality
and a library for game development. Games such as Civilization-IV, Disney’s Toontown
Online, Vega Strike etc. have been built using Python.

3. Machine Learning and Artificial Intelligence


Machine Learning and Artificial Intelligence are the talks of the town as they yield the most
promising careers for the future. We make the computer learn based on past experiences
through the data stored or better yet, create algorithms which makes the computer learn by
itself. The programming language that mostly everyone chooses? It’s Python. Why? Support
for these domains with the libraries that exist already such as Pandas, ScikitLearn, NumPy
and so many more.

4. Data Science and Data Visualization


Data is money if you know how to extract relevant information which can help you take
calculated risks and increase profits. You study the data you have, perform operations and
extract the information required. Libraries such as Pandas, NumPy help you in extracting
information.

You can even visualize the data libraries such as Matplotlib, Seaborn, which are helpful in
plotting graphs and much more. This is what Python offers you to become a Data Scientist.
5. Desktop GUI
We use Python to program desktop applications. It provides the Tkinter library that can be
used to develop user interfaces. There are some other useful toolkits such as the wxWidgets,
Kivy, PYQT that can be used to create applications on several platforms. You can start out
with creating simple applications such as Calculators, To-Do apps and go ahead and create
much more complicated applications.

Python
Programming Lab
9
DEPARTMENT OF MECHANICAL ENGINERING
6. Web Scraping Applications
Python is a savior when it comes to pull a large amount of data from websites which can then
be helpful in various real-world processes such as price comparison, job listings, research
and development and much more. Python has BeautifulSoup which we use to pull such data.
Here’s a full-fledged guide to learn Web scraping with Python.
7. Business Applications

Business Applications are different than our normal applications covering domains such as
e-commerce, ERP and many more. They require applications which are scalable, extensible
and easily readable and Python provides us with all these features. Platforms such as Tryton
is available to develop such business applications.

8. Audio and Video Applications

We use Python to develop applications that can multi-task and also output media. Video and
audio applications such as TimPlayer, Cplay have been developed using Python libraries.
They provide better stability and performance in comparison to other media players.

9. CAD Applications

Computer-Aided Designing is quite challenging to make as many things have to be taken care
of. Objects and their representation, functions are just the tip of the iceberg when it comes to
something like this. Python makes this simple too and the most well-known application for
CAD is Fandango.

10. Embedded Applications

Python is based on C which means that it can be used to create Embedded C software for
embedded applications. This helps us to perform higher-level applications on smaller devices
which can compute Python.The most well-known embedded application could be the
Raspberry Pi which uses Python for its computing. We can also use it as a computer or like a
simple embedded board to perform high-level computations.

b) Installation of Python programming environment: Installation of


Latest Version of Python on windows (python 3.9.1)
Step 1: Download latest version of Python (Python 3.9.1) installer for windows
from python.org

Python
Programming Lab
10
DEPARTMENT OF MECHANICAL ENGINERING

Step 2: Once downloaded run Python installer. Check add python to path and click install now.

Python
Programming Lab
11
DEPARTMENT OF MECHANICAL ENGINERING

Step 3: Once installation is done then open Python shell or IDLE (development
environment for python) from start menu/search bar

Interactive Mode Programming


Invoking the interpreter without passing a script file as a parameter Type text
at the Python prompt as shown and press the Enter

Python
Programming Lab
12
DEPARTMENT OF MECHANICAL ENGINERING
Script Mode Programming
Invoking the interpreter with a script parameter begins execution of the script and
continues until the script is finished
Python files have extension .py
Let us write a simple Python program in a script. Python files have extension .py.
Type the following source code in a 1.py file

Python
Programming Lab
13
DEPARTMENT OF MECHANICAL ENGINERING

Python
Programming Lab
14
DEPARTMENT OF MECHANICAL ENGINERING

Python
Programming Lab
15
DEPARTMENT OF MECHANICAL ENGINERING
c) Installation of Python programming environment: Installation of Anaconda
Navigator

Why anaconda?
• anaconda comes with a lot of libraries so you don’t have to install those libraries or
packages again so it is very user friendly for beginners
• with anaconda there comes an IDE known as Spyder so we will be using Spyder Step

1: Download anaconda from anaconda.org

Step 2: goto Download Anaconda tab

Step 3: download individual edition


Python
Programming Lab
16
DEPARTMENT OF MECHANICAL ENGINERING

Step 4: choose anaconda installer for your OS

Python
Programming Lab
17
DEPARTMENT OF MECHANICAL ENGINERING
Step 5: click on downloaded fine and install

Step 5: click on next after choosing right options , at the end of installation click finish.

Python
Programming Lab
18
DEPARTMENT OF MECHANICAL ENGINERING

Python
Programming Lab
19
DEPARTMENT OF MECHANICAL ENGINERING

Step 6:Open anaconda navigator from start menu/search bar

Step 7: Install and Launch Spyder

Python
Programming Lab
20
DEPARTMENT OF MECHANICAL ENGINERING

Spyder IDE

Python
Programming Lab
21
DEPARTMENT OF MECHANICAL ENGINERING

Conclusion: Thus we have successfully installed Python Programming Environment

Python
Programming Lab
22

You might also like