0% found this document useful (0 votes)
4 views25 pages

Python Practice Programs for Students

The document contains a series of Python programming exercises for Class X students, focusing on various topics such as arithmetic operations, input/output, conditionals, and loops. Each program includes a question, code implementation, and expected output format. The exercises aim to enhance students' coding skills through practical application of Python concepts.

Uploaded by

aadoriya
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)
4 views25 pages

Python Practice Programs for Students

The document contains a series of Python programming exercises for Class X students, focusing on various topics such as arithmetic operations, input/output, conditionals, and loops. Each program includes a question, code implementation, and expected output format. The exercises aim to enhance students' coding skills through practical application of Python concepts.

Uploaded by

aadoriya
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

Class X : Holiday Homework 1 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.1/209
4: #----------------------#
5: # Ques 1: Write a program to perform arithmetic operations
6: #------------------------------------------------------------------------#
7:
8:
9: # Read Values
10: num1 = int( input ( "Enter number 1 :") )
11: num2 = int ( input ( "Enter number 2 :") )
12:
13: # perform arithmetic operations
14: tot = num1 + num2
15: sub = num1 - num2
16: prod = num1 * num2
17: quot = num1 / num2
18: mod = num1 % num2
19: expo = num1 ** num2
20:
21: # Display Results
22: print ( "The sum of the numbers is : ", tot )
23: print ( "The difference of the numbers is : ", sub )
24: print ( "The product of the numbers is : ", prod )
25: print ( "The quotient of the numbers is : ", quot )
26: print ( "The modulus of the numbers is : ", mod )
27: print ( "The exponent value of the numbers is : ", expo )
28:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_01.py Naveen Kataria


Class X : Holiday Homework 2 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.2/214
4: #----------------------#
5: # Ques 2: Write a program to display : name, age, salary.
6: #------------------------------------------------------------------------#
7:
8: # Read Values
9: name = input ( "Enter your name :")
10: age = int ( input ( "Enter your age ( in years ) :") )
11: salary = float ( input ( "Enter your salary :") )
12:
13: # Display Results
14: print ( "Yur name is : ", name )
15: print ( "Your are ", age , " years old.")
16: print ( "You earn Rs. ", salary)
17:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_02.py Naveen Kataria


Class X : Holiday Homework 3 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.2/215
4: #----------------------#
5: # Ques 3: Write a program to calculate the area of a right triangle
6: #------------------------------------------------------------------------#
7:
8:
9: # Read Values
10: base = float ( input ( "Enter base :") )
11: height = float ( input ( "Enter height :") )
12:
13: # perform calculation
14: area = 0.5 * base * height
15:
16: # Display Results
17: print ( "The area of the right triangle is : ", area )
18:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_03.py Naveen Kataria


Class X : Holiday Homework 4 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.2/217
4: #----------------------#
5: # Ques 4: Write a program to check whether a number is positive, negative
6: # or zero
7: #------------------------------------------------------------------------#
8:
9: # Read Values
10: num = int( input ( "Enter a number :") )
11:
12: # Check & Display Results
13: if num > 0:
14: print ( "The number is positive." )
15: elif num < 0:
16: print ( "The number is negative." )
17: else:
18: print ( "The number is zero." )
19:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_04.py Naveen Kataria


Class X : Holiday Homework 5 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.3/217
4: #----------------------#
5: # Ques 5: Write a program to check grade based on marks.
6: #------------------------------------------------------------------------#
7:
8: # Read Values
9: score = int( input ( "Enter your score :") )
10:
11: # Check & Display Results
12: if score >= 90:
13: print ( "Your Grade is : A" )
14: elif score >= 80:
15: print ( "Your Grade is : B" )
16: else :
17: print ( "Your Grade is : C" )
18:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_05.py Naveen Kataria


Class X : Holiday Homework 6 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.1/218
4: #----------------------#
5: # Ques 6: Write a program to check eligibility based on age & height.
6: #------------------------------------------------------------------------#
7:
8: # Read Values
9: age = int( input ( "Enter your age ( in years ) :") )
10: height = float ( input ( "Enter your height ( in Mts ) :") )
11:
12: # Check & Display Results
13: if age >= 18:
14: if height >= 1.5:
15: print ( "You are eligible to ride the roller coaster." )
16: else:
17: print ( "You must be at least 1.5 meters tall." )
18: else :
19: print ( "You must be 18 years or older. Try later !!!" )
20:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_06.py Naveen Kataria


Class X : Holiday Homework 7 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.1/242
4: #----------------------#
5: # Ques 7: Write a program to calculate surface area and volume of a cuboid.
6: #------------------------------------------------------------------------#
7:
8: # Read Values
9: ln = float ( input ( "Enter the length of the cuboid :") )
10: ht = float ( input ( "Enter the height of the cuboid :") )
11: wd = float ( input ( "Enter the width of the cuboid :") )
12:
13: # Calculate Surface Area and Volume
14: surface_area = 2 * (ln * ht + ht * wd + ln * wd)
15: volume = ln * ht * wd
16:
17: # Display Results
18: print ( "Surface Area of the cuboid is : ", surface_area )
19: print ( "Volume of the cuboid is : ", volume )
20:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_07.py Naveen Kataria


Class X : Holiday Homework 8 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.2/242
4: #----------------------#
5: # Ques 8: Write a program to convert height from centimeters into
6: # feet and inches
7: #------------------------------------------------------------------------#
8:
9: # Read Values
10: hgt_cm = float (input ( "Enter your height in centimeters :") )
11: # Convert to Feet and Inches
12: hgt_inches = hgt_cm / 2.54
13: hgt_feet = int ( hgt_inches // 12 )
14: hgt_inches = hgt_inches % 12
15:
16:
17: # Display Results
18: print ( "Your Height is : ", hgt_feet, " feet and ", hgt_inches, " inches" )
19:
20:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_08.py Naveen Kataria


Class X : Holiday Homework 9 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.3/242
4: #----------------------#
5: # Ques 9: Write a program to check whether a number is even or odd.
6: #------------------------------------------------------------------------#
7:
8: # Read Values
9: num = int(input("Enter a number: "))
10:
11:
12: # Check & Display Results
13: if num % 2 == 0:
14: print(num, " is an even number.")
15: else:
16: print(num, " is an odd number.")
17:
18:
19:
20:
21:
22:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_09.py Naveen Kataria


Class X : Holiday Homework 10 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.4/242
4: #----------------------#
5: # Ques 10: Write a program to check whether a person is eligible to vote or not.
6: #------------------------------------------------------------------------#
7:
8: # Read Values
9: age = int(input("Enter your age : "))
10:
11: # Check Eligibility & display Result
12: if age > 18:
13: print("You are eligible to vote.")
14: elif age == 18:
15: print("This is your first time voting. Make it count !.")
16: else :
17: print("You are not eligible to vote.")
18:
19:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_10.py Naveen Kataria


Class X : Holiday Homework 11 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.5/243
4: #----------------------#
5: # Ques 11: Write a program to check whether a number is positive - even / odd or
6: # negative - even/odd or zero.
7: #------------------------------------------------------------------------#
8:
9: # Read Values
10: num = int(input("Enter a number : "))
11:
12: # Check Number & display Result
13: if num > 0:
14: if num % 2 == 0:
15: print("The number is positive and even.")
16: else:
17: print("The number is positive and odd.")
18: elif num < 0:
19: if num % 2 == 0:
20: print("The number is negative and even.")
21: else:
22: print("The number is negative and odd.")
23: else:
24: print("The number is zero and also even..")
25:
26:
27:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_11.py Naveen Kataria


Class X : Holiday Homework 12 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.6/243
4: #----------------------#
5: # Ques 12: Write a program to print numbers from 1 to 10 using
6: # range() function.
7: #------------------------------------------------------------------------#
8:
9: # Start loop & generate numbers
10: for i in range(1, 11):
11: print(i, end=' ')
12:
13:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_12.py Naveen Kataria


Class X : Holiday Homework 13 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.7/243
4: #----------------------#
5: # Ques 13: Write a program find the sum of numbers stored in a list.
6: #------------------------------------------------------------------------#
7:
8: # Create a list of numbers
9: num = [11, 9, 8, 2 , 22, 10, 98, 56, 10 ]
10: total = 0
11:
12: # Loop through each number in the list
13: for i in num:
14: total = total + i # Add each number to the total
15:
16: # Print the result
17: print("The sum of numbers in the list is:", total)
18:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_13.py Naveen Kataria


Class X : Holiday Homework 14 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.8/243
4: #----------------------#
5: # Ques 14: Write a program to check whether a number is an Armstrong number or not.
6:
7: # An Armstrong number is a special number that equals the sum of its digits
8: # each raised to the power of the number of digits in the number.
9: # For example, 153 is an Armstrong number
10: # because 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153.
11: #------------------------------------------------------------------------#
12:
13: # Read Values
14: num = int(input("Enter a number : "))
15:
16: # Initialize variables
17: total = 0
18: temp = num
19:
20: # Extract the digits and calculate the sum of cubes
21: while temp > 0 :
22: digit = temp % 10 # Extract the last digit
23: total += digit ** 3 # Add the cube of the digit to total
24: temp //= 10 # Remove the last digit
25:
26: if num == total:
27: print(f"{num} is an Armstrong number.")
28: else:
29: print(f"{num} is not an Armstrong number.")
30:
31:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_14.py Naveen Kataria


Class X : Holiday Homework 15 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.9/243
4: #----------------------#
5: # Ques 15: Write a program to print the following pattern
6: # 11111
7: # 2222
8: # 333
9: # 44
10: # 5
11: #------------------------------------------------------------------------#
12:
13: # initializing the number of rows
14: rows = 5
15: row_value = 0
16:
17: # outer loop for each row
18: for i in range(rows, 0, -1): # Move rows
19: row_value += 1 # incrementing the row value for each row
20: # inner loop for printing the numbers
21: for j in range(i): # Move columns
22: print(row_value, end="")
23: # moving to the next line after each row
24: print()
25:
26:
27:
28:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_15.py Naveen Kataria


Class X : Holiday Homework 16 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.10/244
4: #----------------------#
5: # Ques 16: Write a program to delete elements from a list
6: #------------------------------------------------------------------------#
7:
8: # Create a list of numbers
9: num = [11, 9, 8, 2 , 22, 10, 98, 56, 10 ]
10:
11: # Print the original list
12: print("Original list:", num)
13:
14: # Delete elements at position 4 from the list
15: # In a list count starts from 0, so position 4 is the 5th element
16: del_num = [Link](4)
17:
18: # Print the deleted item and modified list
19: print("Deleted value :", del_num)
20: print("List after deleting element :", num)
21:
22:
23:
24:
25: #

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_16.py Naveen Kataria


Class X : Holiday Homework 17 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.11/244
4: #----------------------#
5: # Ques 17: Write a program to read temperature for 7 days of a week and
6: # then calculate & display the average temperature for that week.
7: #------------------------------------------------------------------------#
8:
9: # Initialize variables
10: Total_Temp = 0
11:
12: # Loop to read temperature for 7 days
13: for day in range(1, 8):
14: # Read temperature for the day
15: Temp = float(input(f"Enter temperature for day {day} : "))
16: # Add to total temperature
17: Total_Temp += Temp
18:
19: # Calculate average temperature
20: Average_Temp = Total_Temp / 7
21:
22: # Display the average temperature with formatting
23: print(f"The average temperature for the week is : {Average_Temp:.2f}°C")
24:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_17.py Naveen Kataria


Class X : Holiday Homework 18 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.12/244
4: #----------------------#
5: # Ques 18: Write a program to check whether a given number is a palindrome or not.
6: # Palindrome is a number that remains the same when its digits are reversed.
7: # Eg: 121, 12321, etc.
8: #------------------------------------------------------------------------#
9:
10: # Read Values
11: num = int( input("Enter a number: ") )
12:
13: # Initialize Variables
14: temp_num = num
15: rev_num = 0
16:
17: # Traverse the number - Extract the number and build rev_num.
18: while num > 0 :
19: last_digit = num % 10 # Get the last digit
20: rev_num = rev_num * 10 + last_digit # Combine digits to form a new no.
21: num = num // 10 # Remove last digit
22:
23: # Check for palindrome
24: if temp_num == rev_num :
25: print("The number is a Palindrome.")
26: else:
27: print("The number is NOT a Palindrome.")
28:
29:
30:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_18.py Naveen Kataria


Class X : Holiday Homework 19 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.1/270
4: #----------------------#
5: # Ques 19: Write a program to calculate statistical values from sample data
6: #------------------------------------------------------------------------#
7:
8: # Import Statistics Module
9: import statistics as stats
10:
11:
12: # Get a list of random values.
13: ages = [ 25, 30, 35, 45, 50, 55, 30, 30, 60, 55 ]
14:
15: print("The original age data is :", ages)
16:
17: # Genetate statistical data
18: mean = [Link](ages) # find mean of data
19: median = [Link](ages) # find median of data
20: mode = [Link](ages) # find mode of data
21: variance = [Link](ages) # find variance of data
22: std_dev = [Link](ages) # find standard deviation of data
23:
24:
25: # Display the results
26: print("The mean age is :", mean)
27: print("The median age is :", median)
28: print("The mode age is :", mode)
29: print("The variance of age is :", round(variance, 2))
30: print("The standard deviation of age is :", round(std_dev, 2) )
31:
32:
33:
34:
35:
36:
37:
38:
39:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_19.py Naveen Kataria


Class X : Holiday Homework 20 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.2/271
4: #----------------------#
5: # Ques 20: Write a program to plot a scatter plot based on sample data
6: #------------------------------------------------------------------------#
7:
8: # Import plotting Module
9: import [Link] as plt
10:
11: # Some sample data
12: vehicles = [ 10, 20, 25, 40, 50, 60, 70, 75, 80, 85, 90]
13: pollution = [ 30, 20, 90, 96, 100, 300, 375, 490, 400, 500, 505]
14:
15: # Create a scatter plot
16: [Link](vehicles, pollution, color = 'blue', marker = 's')
17:
18: # Set plot labels and title
19: [Link]("Number of vehicles on the road.")
20: [Link]("Air Polliution Levels ( AQI ).")
21: [Link] ("Number of Vehicles Vs. Air Pollution")
22:
23: # Display the plot
24: [Link]()
25:
26:
27:
28:
29:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_20.py Naveen Kataria


Class X : Holiday Homework 21 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No. 3/272
4: #----------------------#
5: # Ques 21: Write a program to plot a bar graph.
6: #------------------------------------------------------------------------#
7:
8: # Import Plotting Module.
9: import [Link] as plt
10:
11:
12: # Some sample data
13: categories = ['Groceries' , 'Utilities', 'Rent', 'Entertainment']
14: expenses = [500, 200, 1000, 300]
15:
16: # Create a scatter plot
17: [Link](categories, expenses, color = 'blue')
18:
19: # Set plot labels and title
20: [Link]("Expense Categories.")
21: [Link]("Monthly Expenses in ( USD) .")
22: [Link] ("Monthly Expense by Category.")
23:
24: # Display the plot
25: [Link]()
26:
27:
28:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_21.py Naveen Kataria


Class X : Holiday Homework 22 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.22/273
4: #----------------------#
5: # Ques 22: Write a program to print a double bar graph
6: #------------------------------------------------------------------------#
7: # Import Plotting & Numpy Modules.
8: import [Link] as plt
9: import numpy as np
10:
11:
12:
13: # Some sample data
14: books_boys = [40, 50, 45, 55]
15: books_girls = [45, 55, 50, 60]
16: quarters = ['Q1', 'Q2', 'Q3', 'Q4']
17:
18: x = [Link]([0,1,2,3]) # x-coordinates for the bars
19:
20: # Create a double bar plot
21: # The x and x+0,4 are used to set bar positions and prevent overlaping
22: [Link](x, books_girls, width=0.4, label="Girls")
23: [Link] (x+0.4, books_boys,width=0.4, label="Boys")
24:
25: # Set plot labels and title
26: [Link]("Quarters.")
27: [Link]("No. of Books Read.")
28: [Link] ("Comparision of Library Books Read by Boys &Girls Quarterly")
29: [Link]()
30:
31: # Set x-ticks to the center of the bars
32: [Link](x + 0.2, quarters)
33:
34:
35: # Display the plot
36: [Link]()
37:
38:
39:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_22.py Naveen Kataria


Class X : Holiday Homework 23 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.1/313
4: #----------------------#
5: # Ques 23: Write a program to crop an image using OpenCV
6: #------------------------------------------------------------------------#
7:
8: # Importing necessary libraries
9: import [Link] as plt
10: import cv2
11:
12:
13: # load original image
14: img = [Link]('[Link]')
15: cropped_img = img[50:300, 50:300] # Cropping a region of interest
16: [Link]([Link](cropped_img, cv2.COLOR_BGR2RGB))
17: [Link]('on') # show axes
18: [Link]("cropped image")
19: [Link]()

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_23.py Naveen Kataria


Class X : Holiday Homework 24 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.1/314
4: #----------------------#
5: # Ques 24: Write a program to change the pixel value to green
6: # (hide part of the image)
7: #------------------------------------------------------------------------#
8:
9: # Importing necessary libraries
10: import [Link] as plt
11: import cv2
12:
13:
14: # load original image
15: img = [Link]('[Link]')
16: # Change pixel value to green
17: img[50:3000, 50:3000] = [0, 255, 0]
18: [Link]([Link](img, cv2.COLOR_BGR2RGB))
19: [Link]('on') # show axes
20: [Link]("pixel hidden")
21: [Link]()

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_24.py Naveen Kataria


Class X : Holiday Homework 25 Sub : AI (Python )

1: #------------------------------------------------------------------------#
2: # Python Programs for Practice
3: # Program No.2/314
4: #----------------------#
5: # Ques 25: Write a program to extract the part of an image
6: #------------------------------------------------------------------------#
7:
8: # Importing necessary libraries
9: import [Link] as plt
10: import cv2
11:
12:
13: # load and display original image
14: img = [Link]('[Link]')
15: [Link]([Link](img, cv2.COLOR_BGR2RGB))
16: [Link]('on') # show axes
17: [Link]("Forest")
18: [Link]()
19:
20: # Extract part of the image
21: img = [Link]('[Link]')
22: giraffe = img[100:200, 100:200] # Extracting a region of interest
23: [Link]([Link](giraffe, cv2.COLOR_BGR2RGB))
24: [Link]('on') # show axes
25: [Link]("giraffe")
26: [Link]()
27:
28:

I:\##_PyCode_Local\IP_CVS_Project\Other_10AI\10_Prg_25.py Naveen Kataria

You might also like