Qwerty
Qwerty
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.
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.
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.
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.
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
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)