0% found this document useful (0 votes)
8 views5 pages

Qwerty

The document provides an introduction to Python, covering its basics, installation, and how to write code, including arithmetic operations and functions. It also includes a lab focused on performing arithmetic operations and a statistical analysis lab that calculates mean, median, mode, and box plot visualization using Python. The labs emphasize the importance of arithmetic and statistical operations in programming and data analysis.

Uploaded by

saadghaffar97
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)
8 views5 pages

Qwerty

The document provides an introduction to Python, covering its basics, installation, and how to write code, including arithmetic operations and functions. It also includes a lab focused on performing arithmetic operations and a statistical analysis lab that calculates mean, median, mode, and box plot visualization using Python. The labs emphasize the importance of arithmetic and statistical operations in programming and data analysis.

Uploaded by

saadghaffar97
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/ 5

LAB 1

Basics of Python
1. What is Python?
Python is a popular programming language. It's easy to learn and use. You can do many things
with Python, like making websites, analyzing data, and creating games.

2. How to Get Python


You can download Python for free from the internet. Go to python.org and follow the instructions
to install it on your computer.

3. Starting Python
Once you have Python installed, you can start it by clicking on the Python icon or typing
"python" in your computer's search bar. This opens up a window where you can type in Python
code and see what happens.

4. Writing Python Code


Python code is written in a way that's easy to understand. Here are some basic things to know:

Indentation: Python uses spaces to organize code. You need to indent your code properly to
make it work.
Comments: You can add notes to your code using the "#" symbol. These notes are ignored by
Python.
Variables: Variables are like boxes where you can store things. You can give them names and
put different types of information inside them.
5. Doing Things in Python
Python can do lots of stuff. Here are a few examples:

Math: You can do math with Python, like adding, subtracting, multiplying, and dividing numbers.
Making Decisions: You can tell Python to do different things depending on what's happening,
like "if this, then do that."
Repeating Stuff: You can make Python do the same thing over and over again using loops.
6. Making Your Own Functions
Sometimes you want to do the same thing many times. Instead of writing the same code over
and over, you can create a function. A function is like a recipe that tells Python how to do
something. You can use functions to make your code shorter and easier to understand.
LAB 2
Arithmetic Operations in Python
In this lab, we explored basic arithmetic operations using Python.

Addition Operation
Addition is a fundamental arithmetic operation in Python. It is performed using the + operator,
and it adds two numbers together. In Python, addition can be applied to numeric data types
such as integers, floats, and complex numbers.

Multiplication Operation
Multiplication is another fundamental arithmetic operation in Python. It is performed using the *
operator, and it multiplies two numbers together. Similar to addition, multiplication can be
applied to various numeric data types in Python.

Understanding Arithmetic Operations


Arithmetic operations in Python follow standard rules of arithmetic, including operator
precedence. Python evaluates expressions based on the order of operations, where
multiplication and division are performed before addition and subtraction. Additionally, Python
supports various built-in functions for arithmetic operations, such as pow() for exponentiation
and abs() for absolute value.

Conclusion
Arithmetic operations are essential components of programming in Python. They allow us to
perform calculations, manipulate data, and solve mathematical problems efficiently. By
understanding how arithmetic operations work in Python, we gain the ability to write more
complex programs and perform a wide range of computations.
EXAMPLE

LAB 3
Data Analysis Lab: Mean, Median, Mode, and Box Plot
In this lab, we performed basic statistical analysis on a simple dataset using Python.

Mean Calculation
The mean (average) of the dataset is calculated by summing all values and dividing by the total
number of values. For our dataset, the mean is approximately 32.5.

Median Calculation
The median is the middle value of the dataset when it is ordered from least to greatest. If there
is an even number of values, the median is the average of the two middle values. For our
dataset, the median is 32.5.

Mode Calculation
The mode is the value(s) that appear most frequently in the dataset. For our dataset, the
mode(s) is/are 10 with a frequency of 1.

Box Plot Analysis


A box plot provides a visual summary of the dataset's distribution. It displays the minimum, first
quartile (Q1), median, third quartile (Q3), and maximum values. Additionally, it can identify
outliers in the data.

Minimum: 10
First Quartile (Q1): 18.75
Median: 32.5
Third Quartile (Q3): 47.5
Maximum: 55

CODE:
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

# Create a simple dataset


data = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]

mean_value = np.mean(data)
print("Mean:", mean_value)

median_value = np.median(data)
print("Median:", median_value)
mode_result = stats.mode(data)
mode_value = mode_result.mode
mode_count = mode_result.count
print("Mode:", mode_value, "with a frequency of", mode_count)

plt.boxplot(data)
plt.title('Box Plot of Data')
plt.ylabel('Values')
plt.show()

q1 = np.percentile(data, 25)
q3 = np.percentile(data, 75)
data_min = np.min(data)
data_max = np.max(data)

print("First Quartile (Q1):", q1)


print("Third Quartile (Q3):", q3)

You might also like