Exp 0
Exp 0
BASICS OF PYTHON
(21IR009)
Aim:
1) Learn the procedure to Install Python, creating a Project in PyCharm and
add packages.
2) To code examples for Python Programming, NumPy and Matplotlib
Packages.
Software and Libraries required:
1. PyCharm IDE with Python 3.7
2. Libraries used:
a) NumPy
b) Matplotlib
Procedure:
• Launch PyCharm and create a new project.
• If PyCharm is not available, we can download it from
https://www.jetbrains.com/pycharm/.
• We can also install the required packages inside the PyCharm.
• Creating a new page leads us to a new environment where we can start typing
our code.
• Once the code is complete, run the program and we can get the result what
we expected.
• If we get error, rectify it and run again.
Programs:
i. If-else program
Program 1-Finding the grade:
grade = int(input("Enter your grade: "))
print("Your grade is below:")
if grade >= 90:
print("A")
elif grade >= 80:
print("B")
elif grade >= 70:
print("C")
elif grade >= 60:
print("D")
else:
print("F")
Output:
Enter your grade: 78
Your grade is below:
C
Program 2-Countdown:
num = 5
while num > 0:
print(f"Countdown: {num}")
num -= 1
Output:
Countdown: 5
Countdown: 4
Countdown: 3
Countdown: 2
Countdown: 1
iv. NumPy program:
Program 1-Squaring an array:
import numpy as np
arr = np.arange(1, 6)
squared_arr = np.square(arr)
print("Original array:", arr)
print("Squared array:", squared_arr)
Output:
Original array: [1 2 3 4 5]
Squared array: [ 1 4 9 16 25]