LAB MANUAL:1
Introduction to Python Programming and Environment Setup
This lab is designed to introduce students to the fundamentals of Python programming,
focusing on understanding the Python environment, writing the first program, using
variables, taking user input, performing arithmetic operations, and applying basic
decision-making. By the end of this lab, students will be able to write, execute, and
debug simple Python programs relevant to engineering and data analysis.
Tools:
Tool / Software Description / Purpose
Python (Version 3.8 or The main programming language used for all experiments
above) and problem-solving tasks.
A free, cloud-based environment provided by Google to
Google Colab
write and execute Python code online without installation.
Jupyter Notebook An interactive development environment used for writing
(Optional) and testing Python code locally.
Web Browser (Google Required to access Google Colab or any online Python
Chrome / Edge) environment.
Anaconda Distribution A package manager that installs Python and essential data
(Optional) science libraries (NumPy, Pandas, Matplotlib).
Theoretical Background
1. Introduction to Python:
Python is a high-level, interpreted programming language known for its readability,
flexibility, and wide range of applications in data science and engineering.
Unlike compiled languages such as C++ or Java, Python executes code line by line,
making debugging and learning easier.
Key features:
Simple and English-like syntax.
Dynamically typed (no explicit type declaration).
Platform-independent and open-source.
Vast libraries for numerical and data analysis (NumPy, Pandas, Matplotlib)
Structure of a Python Program:
Explanation:
# is a comment (ignored by the interpreter).
print() displays text or variable values.
Variables and Data Types:
“A variable is a name that refers to a value stored in the computer’s memory.”
Think of a variable as a container or label used to store data that can change or be
used in calculations later.
Explanation:
xand y are variables storing numeric values.
zstores the result of x + y.
The print(z) statement displays the value stored in z.
In Python, you do not need to declare the data type of a variable explicitly.
The type is automatically detected by the interpreter based on the value assigned.
This is called dynamic typing.
What is a Data Type?
A data type defines what kind of value a variable can hold and what operations can
be performed on it.
Python has several built-in data types, which are automatically assigned based on
the value stored.
Common Python Data Types:
Data
Category Example Description / Use
Type
Whole numbers without
Numeric int a = 10
decimals.
Numbers with decimal
float b = 3.14
points.
Sequence of characters
Text str name = "Nahiya"
(string).
Logical values: True or
Boolean bool flag = True
False.
Sequence / Ordered, mutable collection
list nums = [1, 2, 3]
Collection of items.
Ordered, immutable
tuple t = (1, 2, 3)
collection.
Set set s = {1, 2, 3} Unordered, unique elements.
student = {"name": "Ali", Key-value pairs for
Dictionary dict
"age": 21} structured data.
Represents no value or null
NoneType None x = None
object.
Inputs and Outputs Function:
· print() → Used for displaying output.
· input() → Used for taking input from the user.
Operators:
Operator Type Example Meaning
Arithmetic +, -, *, /, % Mathematical operations
Comparison >, <, ==, != Compare values
Assignment =, +=, -= Assign values
Logical and, or, not Combine conditions
Conditional Statements:
LAB TASK:
1. Print your name, age, and a short introduction using Python variables.
2. Write a Python program to calculate the density of a liquid sample using the
formula.
3. Create a program that takes two numbers as input and performs all
arithmetic operations on them.
4. Execute a program that takes two numbers and prints whether the first
number is greater than, less than, or equal to the second number?