0% found this document useful (0 votes)
38 views9 pages

Class 10 Programs for Project File

The document contains a series of Python programming exercises for Class 10 students at Delhi Public School, Hyderabad. Each exercise includes a specific task, such as calculating salaries, generating patterns, checking prime numbers, and manipulating arrays, along with the corresponding Python code. The exercises cover a range of topics including basic programming concepts, data manipulation, and the use of libraries like NumPy and Matplotlib.

Uploaded by

rheasharma146
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)
38 views9 pages

Class 10 Programs for Project File

The document contains a series of Python programming exercises for Class 10 students at Delhi Public School, Hyderabad. Each exercise includes a specific task, such as calculating salaries, generating patterns, checking prime numbers, and manipulating arrays, along with the corresponding Python code. The exercises cover a range of topics including basic programming concepts, data manipulation, and the use of libraries like NumPy and Matplotlib.

Uploaded by

rheasharma146
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/ 9

Delhi Public School, Hyderabad

Class 10 Artificial Intelligence


PROGRAMS FOR PRACTICAL FILE
1. Write a python program to input the name, age and basic salary of an employee and calculate
the total salary by adding 10% DA and 10%HRA to the basic salary.
Code:
# Input employee details
name = input("Enter the employee's name: ")
age = int(input("Enter the employee's age: "))
basic_salary = float(input("Enter the employee's basic salary: "))
# Calculate DA and HRA
da = 0.10 * basic_salary # 10% DA
hra = 0.10 * basic_salary # 10% HRA
# Calculate total salary
total_salary = basic_salary + da + hra
# Output the results
print("\nEmployee Name:", name)
print("Employee Age:", age)
print("Basic Salary: ", round(basic_salary, 2))
print("Total Salary (including DA and HRA): ", round(total_salary, 2))
2. Write a python program to generate the pattern

Code:
# Number of rows for the pattern
rows = 5

# Generate the pattern

for i in range(1, rows + 1):

# Print i asterisks

for j in range(i):

print('*', end=' ')

# Move to the next line

print()

3. Write a python program to check whether a number is prime or not.


Code:
n = int(input("Enter a number: "))

if n <= 1:

print(n, "is not a prime number.")

else:

is_prime = True

# Loop through all numbers from 2 to n-1 to check for factors

for i in range(2, n):

# Check if n is divisible by i

if n % i == 0:

is_prime = False

# Exit the loop early since we found a factor

break

if is_prime:

print(n, "is a prime number.")

else:

print(n, "is not a prime number.")

4. Write a python program to input two numbers and find their HCF and LCM.
Code:

# Input two numbers from the user

num1 = int(input("Enter the first number: "))

num2 = int(input("Enter the second number: "))

# Find HCF

hcf = 1
for i in range(1, min(num1, num2) + 1):

if num1 % i == 0 and num2 % i == 0:

hcf = i # Update HCF if i is a common factor

# Find LCM using the formula

lcm = (num1 * num2) // hcf

# Print the results

print("HCF of", num1, "and", num2, "is:", hcf)

print("LCM of", num1, "and", num2, "is:", lcm)


5. Write a python program to find numbers that are divisible by 7 and multiples of 5 between
1200 and 2200.
Code:

for number in range(1200, 2201):

# Check if the number is divisible by 7 and a multiple of 5

if number % 7 == 0 and number % 5 == 0:

print(number)

6. Write a python program to determine whether a year is leap year or not.


Code:

year = int(input("Enter a year: "))

# Check if the year is a leap year

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):

print(year, "is a leap year.")

else:

print(year, "is not a leap year.")

7. Program to check whether a number is palindrome.


Code:

# Input a number from the user

num = input("Enter a number: ")

# Check if the number is the same when reversed

if num == num[::-1]:

print(num, "is a palindrome.")

else:

print(num, "is not a palindrome.")


8.Write a program to add the elements of two lists.
Code:

list1 = [1, 2, 3]

list2 = [4, 5, 6]

added_list = [ ]

# Initialize an empty list to store the results


for i in range(len(list1)):

# Loop through the lists and add corresponding elements

added_list.append(list1[i] + list2[i])

print(added_list)

# Print the result

9. Write a python program to perform addition and multiplication on two #different arrays.

Code:

import numpy as np

# Create two arrays

array1 = np.array([1, 2, 3, 4])

array2 = np.array([5, 6, 7, 8])


# Perform addition

addition = array1 + array2

# Perform multiplication

multiplication = array1 * array2

# Print the results

print("Array 1:", array1)

print("Array 2:", array2)

print("The result of addition is: ", addition)

print("The result of multiplication is: ", multiplication)

10. Write a python program to create one dimensional array with values ranging from 10 to 100, i.e.,
multiples of 10

Code:
import numpy as np

# Create a one-dimensional array with multiples of 10 from 10 to 100

array = np.arange(10, 101, 10)

# Print the array

print("Array with multiples of 10 from 10 to 100:", array)

11. Write a python program to create a two dimensional array(2X3) with random integer values less than

Code:

import numpy as np
# Create a 2x3 array with random integers less than 20

array_2d = np.random.randint(0, 20, (2, 3))

# Print the array

print("Two-dimensional array (2x3) with random integers less than 20:")

print(array_2d)

12. Write a program to find the maximum value in each row and each column of a 2D array.

Code:

# Create a 2D array (3 rows and 4 columns)

array_2d = [

[5, 12, 3, 8],

[7, 1, 6, 14],

[10, 4, 11, 9]

# Initialize lists to hold the maximum values

max_in_rows = []

max_in_columns = []

# Find the maximum value in each row

for row in array_2d:

max_in_rows.append(max(row))

# Find the maximum value in each column

for col in range(len(array_2d[0])): # Assume all rows have the same number of columns

column_values = [array_2d[row][col] for row in range(len(array_2d))]

max_in_columns.append(max(column_values))

# Print the results

print("Original 2D Array:")

for row in array_2d:

print(row)

print("\nMaximum value in each row:")

print(max_in_rows)

print("\nMaximum value in each column:")

print(max_in_columns)
13. Write a program to sort the elements of an array in descending order and find the sum of all values
array.

Code:

# Create an array with some values

array = [5, 12, 3, 8, 7, 1]

# Sort the array in descending order

sorted_array = sorted(array, reverse=True)

# Calculate the sum of all values in the array

total_sum = sum(array)

# Print the results

print("Original Array:", array)

print("Sorted Array (Descending Order):", sorted_array)

print("Sum of all values in the array:", total_sum)

14. Write a program to calculate mean, median and mode using Numpy

Code:

import statistics

ages=[20,35,32,40,80,79,64,50]

mean=statistics.mean(ages) #calculate the mean

median=statistics.median(ages) #calculate the median

mode=statistics.mode(ages) # calculate the mode

print("Mean: ",mean)

print("Median: ",median)

print("Mode: ",mode)
15. Write a program to display a scatter chart for the following points (2,5), (9,10),(8,3),(5,7),(6,18).

Code:

import matplotlib.pyplot as plt

# Define the points

x = [2, 9, 8, 5, 6]

y = [5, 10, 3, 7, 18]

# Create the scatter chart

plt.scatter(x, y, color='red', marker='x')

# Add titles and labels


plt.title('Scatter Chart for given points')

plt.xlabel('X-axis')

plt.ylabel('Y-axis')

# Set limits for better visibility

plt.xlim(0, 10)

plt.ylim(0, 20)

# Show grid

plt.grid()

# Display the plot

plt.show()

16. Write a program to display line chart from (2,5) to (9,10).

code:

import matplotlib.pyplot as plt

# Define the points

x = [2, 9]

y = [5, 10]

# Create the line chart

plt.plot(x, y, marker='p', color='blue', linestyle='--')

# Add titles and labels

plt.title('Line Chart from (2, 5) to (9, 10)')

plt.xlabel('X-axis')

plt.ylabel('Y-axis')

# Set limits for better visibility

plt.xlim(0, 10)

plt.ylim(0, 12)

# Show grid

plt.grid()

# Display the plot

plt.show()

17. Read csv file saved in your system and display its information

Code:

import pandas as pd
# Read the CSV file

data = pd.read_csv('C:\\Users\\USER\\Desktop\\examslist.csv')

print(data)

18. Read csv file saved in your system and display first 5 records.

Code:

import pandas as pd

# Specify the full path to your CSV file on the Desktop

file_path = r'C:\Users\USER\Desktop\Sales Data.csv'

# Read the CSV file

data = pd.read_csv(file_path)

# Display the first 10 rows

print(data.head(5))

19. Write a program to read an image and display using Python.

Code:

import cv2

import numpy as np

import matplotlib.pyplot as plt

# To load or read an image into computers memory, we use imread() function from OpenCV library

image = cv2.imread(r'C:\Users\USER\Pictures\Screenshots\logo.png')

cv2.imshow('Image', image)

# Wait for a key press and close the window

cv2.waitKey(0)

cv2.destroyAllWindows()

20. Write a program to read an image and identify its shape (height, width, channel) using computer vi

Code:

import cv2

import matplotlib.pyplot as plt

import numpy as np

# Read the image. OpenCV tores images in BGR order rather than RGB

image = cv2.imread(r'C:\Users\USER\Pictures\Screenshots\flower.jpg')

# convert image to RGB and Display the image

plt.imshow(cv2.cvtColor(image,cv2.COLOR_BGR2RGB))
plt.axis('on')

plt.show()

height,width,channels=image.shape

print("Height: ",height)

print("Width: ",width)

print("Channels: ",channels) # Color channels (example: 3 for RGB, 1 for grayscale)

You might also like