0% found this document useful (0 votes)
6 views23 pages

Practicle FIle

The document contains an index of 21 programming exercises, each focusing on different programming concepts such as calculating simple interest, manipulating lists, and creating arrays using Python. Each program includes code snippets and expected outputs for practical understanding. The exercises cover a range of topics from basic arithmetic operations to array manipulations using NumPy.

Uploaded by

cidife7365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views23 pages

Practicle FIle

The document contains an index of 21 programming exercises, each focusing on different programming concepts such as calculating simple interest, manipulating lists, and creating arrays using Python. Each program includes code snippets and expected outputs for practical understanding. The exercises cover a range of topics from basic arithmetic operations to array manipulations using NumPy.

Uploaded by

cidife7365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

0

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)

Addition of Element at specific Position (using Insert Method)


List.insert(3, 12)
List.insert(0, 'Kabir')
print("\nList after Insert Operation: ")
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)

Addition of multiple elements to the List at the end (using Extend


Method)
List.extend([8, 'Artificial', 'Intelligence'])
print("\nList after Extend Operation: ")
print(List)

OUTPUT:

5
Program 5 (Add Elements to a List)
List = []
print("Initial blank List: ")
print(List)

Addition of Elements in the List


List.append(1)
List.append(2)
List.append(4)
print("\nList after Addition:")
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)

Using Slice operation


Sliced_List = List[3:8]
print("\nSlicing elements in a range 3-8: ")
print(Sliced_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)

Removing elements from List using Remove() method


List.remove(5)
List.remove(6)
print("\nList after Removal:")
print(List)print("Datatype of simple interest:", type(simple_interest))

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)

Removing element at a specific location from Set using the pop()


method
List.pop(2)
print("\nList after pop: ")
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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy