0% found this document useful (0 votes)
8 views

PYTHON PROGRAMS

The document contains a series of Python programs demonstrating various programming concepts, including array creation, list manipulation, and basic input/output operations. Each program is accompanied by its code and expected output. Topics covered include creating arrays with NumPy, checking eligibility for voting, calculating simple interest, and determining the area and perimeter of geometric shapes.
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)
8 views

PYTHON PROGRAMS

The document contains a series of Python programs demonstrating various programming concepts, including array creation, list manipulation, and basic input/output operations. Each program is accompanied by its code and expected output. Topics covered include creating arrays with NumPy, checking eligibility for voting, calculating simple interest, and determining the area and perimeter of geometric shapes.
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

‭ IVYANSH AGRAWAL‬

D
‭CLASS X-E‬
‭ROLL NO. 9‬

‭YTHON‬
P
PROGRAMS‬

PROGRAM 1‬

Creating an array of evenly spaced values‬

CODE:‬

‭import numpy as np‬


‭array1=np.arange(0,10,2)‬
‭print(array1)‬

OUTPUT:‬

PROGRAM 2‬

Creating a full array‬

CODE:‬

‭import numpy as np‬


‭full_array=np.full ((2,3),5)‬
‭print(full_array)‬

OUTPUT:‬

PROGRAM 3‬

Removing elements from a List‬

CODE:‬

‭List = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,12]‬


‭print("Initial List: ")‬
‭print(List)‬
‭List.remove(5)‬
‭List.remove(6)‬
‭print("\nList after Removal:")‬
‭print(List)‬

OUTPUT:‬

PROGRAM 4‬

A program to check if a person can vote‬

CODE:‬

‭age = int(input("Enter your age: "))‬


‭if age>=18:‬
‭print("You're eligible to vote")‬
‭else:‬
‭print("You're not eligible to vote")‬

OUTPUTS:‬

PROGRAM 5‬

Program to calculate the Simple Interest‬

CODE:‬

‭principle_amount = int(input("Enter Principle Amount: "))‬


‭roi = int(input("Enter Rate of Interest Per Annum: "))‬
‭time = int(input("Enter Time Period (In Years): "))‬
‭simple_interest = (principle_amount * roi * time)/100‬
‭print("Simple Interest : ", simple_interest)‬

OUTPUT:‬

PROGRAM 6‬

Addition of Elements in a List‬

CODE:‬

‭List = []‬
‭print("Initial blank List: ")‬
‭print(List)‬
‭List.append(1)‬
‭List.append(2)‬
‭List.append(4)‬
‭print("\nList after Addition :")‬
‭print(List)‬

OUTPUT:‬

PROGRAM 7‬

Slicing a List‬

CODE:‬

‭List= ['G','O','O','D','M','O', 'R','N','I','N','G']‬


‭print("Initial List: ")‬
‭print(List)‬
‭Sliced_List = List[3:8]‬
‭print("\nSlicing elements in a range 3-8: ")‬
‭print(Sliced_List)‬

OUTPUT:‬

PROGRAM 8‬

Program to check if a number is positive or negative or‬

zero‬

CODE:‬

‭num = float(input("Enter a number: "))‬


‭if num >= 0:‬
‭if num == 0:‬
‭print("Zero")‬
‭else:‬
‭print("Positive number")‬
‭else:‬
‭print("Negative number")‬

OUTPUT:‬

PROGRAM 9‬

Program to calculate Area and Perimeter of a Rectangle‬

CODE:‬

‭L=int(input("Length: "))‬
‭B=int(input("Breadth: "))‬
‭Area=L*B‬
‭Perimeter=2*(L+B)‬
‭print("Area:",Area)‬
‭print("Perimeter:",Perimeter)‬

OUTPUT:‬

PROGRAM 10‬

Removing elements from list using pop() feature‬

CODE:‬

‭List = [1,2,3,4,5,6,7,8,9,10]‬
‭list.pop(List)‬
‭print("List after popping an element: ")‬
‭print(List)‬
‭List.pop(2)‬
‭print("\nContent after pop ")‬
‭print(List)‬

OUTPUT:‬

PROGRAM 11‬

Creating an array of zeros‬

CODE:‬

‭import numpy as np‬


‭array1 = np.zeros((2,3))‬
‭print(array1)‬

OUTPUT:‬

PROGRAM 12‬

Creating 1-D Array‬

CODE:‬

‭import numpy as np‬


‭array1=np.array([10,20,30,40,50])‬
‭print(array1)‬

OUTPUT:‬

PROGRAM 13‬

Creating an empty array‬

CODE:‬

‭import numpy as np‬


‭empty_array=np.empty((3,2))‬
‭print(empty_array)‬

OUTPUT:‬

PROGRAM 14‬

Program to check the grade of a student‬

CODE:‬

‭marks = int(input("Enter your Marks: "))‬


‭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:‬

PROGRAM 15‬

Creating an array with random values‬

CODE:‬

‭import numpy as np‬


‭random_array=np.random.random((2,2))‬
‭print(random_array)‬

OUTPUT:‬

PROGRAM 16‬

Calculate Area and Perimeter of a Square‬

CODE:‬

‭side = int(input("Enter side of square: "))‬


‭area = side*side‬
‭perimeter = side*4‬
‭print("Perimeter is: ", perimeter)‬
‭print("Area is: ", area)‬

OUTPUT:‬

PROGRAM 17‬

Creating and adding elements to a List‬

CODE:‬

‭List = [1,2,3,4]‬
‭print("Initial List: ")‬
‭print(List)‬
‭List.insert(3, 12)‬
‭List.insert(0, 'Kabir')‬
‭print("\nList after Insert Operation: ")‬
‭print(List)‬

OUTPUT:‬

PROGRAM 18‬

Creating an array of ones‬

CODE:‬

‭import numpy as np‬


‭array1=np.ones((3,3))‬
‭print(array1)‬

OUTPUT:‬

PROGRAM 19‬

Addition of multiple elements to a List‬

CODE:‬

‭List = [1,2,3,4]‬
‭print("Initial List: ")‬
‭print(List)‬
‭List.extend([8, 'Artificial', 'Intelligence'])‬
‭print("\nList after Extend Operation: ")‬
‭print(List)‬

OUTPUT:‬

PROGRAM 20‬

Creating a range array‬

CODE:‬

‭import numpy as np‬


‭array1=np.arange(8)‬
‭print(array1)‬

OUTPUT:‬

PROGRAM 21‬

Creating 2-D array‬

CODE:‬

‭import numpy as np‬


‭array1=np.array([[10,20,30,40,50],[100,200,300,400,500]])‬
‭print(array1)‬

OUTPUT:‬

THANK YOU‬

CODE:‬

print("thank you")‬

OUTPUT:‬

You might also like