Practicle FIle
Practicle FIle
Index of Programs
S.NO Name of Programs Page
No.
1. Calculate Simple Interest 2
2. Calculate Area and Perimeter of a Rectangle 3
3. Insert Elements in a List 4
4. Extend List with Multiple Elements 5
5. Add Elements to a List 6
6. Check if a Number is Positive 7
7. Using Slicing from a List 8
8. Print Elements from a Point to End 9
9. Removing Elements from a List 10
10. Pop Elements from a List 11
11. Creating a 2-D Array 12
12. Creating a 1-D Array 13
13. Check if a Number is Positive, Negative, or Zero 14
14. Check Student Grade 15
15. Voting Eligibility 16
16. Creating a Full Array 17
17. Creating an Empty Array 18
18. Creating an Array with Random Values 19
19. Creating an Array of Zeros 20
20. Creating an Array of Ones 21
21. Creating an Array of Evenly Spaced Values 22
1
Program 1 (Calculate Simple Interest)
Code to calculate the Simple Interest
principle_amount = 2000
ri = 4.5
time = 10
simple_interest = (principle_amount * ri * time) / 100
print("Datatype of principle amount:", type(principle_amount))
print("Datatype of rate of interest:", type(ri))
print("Value of simple interest:", simple_interest)
print("Datatype of simple interest:", type(simple_interest))
OUTPUT:
2
Program 2
(Calculate Area and Perimeter of a Rectangle)
To calculate Area and Perimeter of a rectangle
L = int(input("Length: "))
B = int(input("Breadth: "))
Area = L * B
Perimeter = 2 * (L + B)
print("Area:", Area)
print("Perimeter:", Perimeter)
OUTPUT:
3
Program 3 (Insert Elements in a List)
Creating a List
List = [1, 2, 3, 4]
print("Initial List: ")
print(List)
OUTPUT:
4
Program 4 (Extend List with Multiple Elements)
Addition of multiple elements to the list
List = [1, 2, 3, 4]
print("Initial List: ")
print(List)
OUTPUT:
5
Program 5 (Add Elements to a List)
List = []
print("Initial blank List: ")
print(List)
OUTPUT:
6
Program 6 (Check if a Number is Positive)
Check if the number is positive, we print an appropriate message
num = 3
if num > 0:
print(num, "is a positive number.")
print("This is always printed")
num = -1
if num > 0:
print(num, "is a positive number.")
print("This is always printed")
OUTPUT:
7
Program 7 (Using Slicing from a List)
Using Slicing from a List
List = ['G', 'O', 'O', 'D', 'M', 'O', 'R', 'N', 'I', 'N', 'G']
print("Initial List: ")
print(List)
OUTPUT:
8
Program 8 (Print Elements from a Point to End)
Print elements from a pre-defined point to end
List = ['G', 'O', 'O', 'D', 'M', 'O', 'R', 'N', 'I', 'N', 'G']
Sliced_List = List[5:]
print("Elements sliced from 5th element till the end:")
print(Sliced_List)
OUTPUT:
9
Program 9 (Removing Elements from a List)
Removing elements from a List
List = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
print("Initial List: ")
print(List)
OUTPUT:
10
Program 10 (Pop Elements from a List)
Removing element from the Set using the pop() method
List = [1, 2, 3, 4, 7, 8, 9, 10, 11, 12]
List.pop()
print("\nList after popping an element: ")
print(List)
OUTPUT:
11
Program 11 (Creating a 2-D Array)
import numpy as np
array1 = np.array([[10, 20, 30, 40, 50], [100, 200, 300, 400, 500]])
print(array1)
OUTPUT:
12
Program 12 (Creating a 1-D Array)
import numpy as np
array1 = np.array([10, 20, 30, 40, 50])
print(array1)
OUTPUT:
13
Program 13
(Check if a Number is Positive, Negative, or Zero)
In this program, we input a number check if the number is
positive or negative or zero and display an appropriate message.
num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
OUTPUT:
14
Program 14 (Check Student Grade)
To check the grade of a student
marks = 60
if marks > 75:
print("You get an A grade")
elif marks > 60:
print("You get a B grade")
else:
print("You get a C grade")
OUTPUT:
15
Program 15 (Voting Eligibility)
A program to check if a person can vote
age = int(input("Enter Your Age: "))
if age >= 18:
print("You are eligible to vote")
else:
print("You are not eligible to vote")
OUTPUT:
16
Program 16 (Creating a Full Array)
import numpy as np
full_array = np.full((2, 3), 5)
print(full_array)print("Datatype of simple interest:", type(simple_interest))
OUTPUT:
17
Program 17 (Creating an Empty Array)
import numpy as np
empty_array = np.empty((3, 2))
print(empty_array)
OUTPUT:
18
Program 18
(Creating an Array with Random Values)
import numpy as np
random_array = np.random.random((2, 2))
print(random_array)
OUTPUT:
19
Program 19 (Creating an Array of Zeros)
import numpy as np
array1 = np.zeros((2, 3))
print(array1)
OUTPUT:
20
Program 20 (Creating an Array of Ones)
import numpy as np
array1 = np.ones(8)
print(array1)
OUTPUT:
21
Program 21
(Creating an Array of Evenly Spaced Values)
import numpy as np
array1 = np.arange(0, 10, 2)
print(array1)
OUTPUT:
22