0% found this document useful (0 votes)
5 views15 pages

Python Program.

The document outlines a practical lab program for 10th-grade students, detailing various Python programming exercises. Each exercise includes an aim, algorithm, program code, and expected output, covering topics such as calculating area, factorial, leap year checking, and data visualization. The document serves as a comprehensive guide for students to learn and implement basic Python programming concepts.

Uploaded by

mithshy2011
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)
5 views15 pages

Python Program.

The document outlines a practical lab program for 10th-grade students, detailing various Python programming exercises. Each exercise includes an aim, algorithm, program code, and expected output, covering topics such as calculating area, factorial, leap year checking, and data visualization. The document serves as a comprehensive guide for students to learn and implement basic Python programming concepts.

Uploaded by

mithshy2011
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

PRACTICAL LAB PROGRAM- X STD

1) Write a Python program to calculate the area and circumference of a circle.

Aim

To write a Python program to find the area and circumference of a circle for a given radius.

Algorithm

1. Start
2. Prompt the user to enter the radius
3. Read the radius value
4. Calculate area using:
area = 3.14 × radius × radius
5. Calculate circumference using:
circumference = 2 × 3.14 × radius
6. Display the area
7. Display the circumference
8. Stop

Program

radius = float(input("Enter the radius of the circle: "))

area = 3.14 * radius * radius


circumference = 2 * 3.14 * radius

print("Area of the circle:", area)


print("Circumference of the circle:", circumference)

Result

The program was executed successfully and the area and circumference of the circle were calculated.

Output

Enter the radius of the circle: 3


Area of the circle: 28.26
Circumference of the circle: 18.84

[Link] a Python program to find the factorial of a number

Aim:

To write a Python program to calculate the factorial of a given positive integer.

Algorithm:

1. Start
2. Input a positive integer num
3. Initialize a variable factorial to 1
4. For each integer i from 1 to num (inclusive):
o Multiply factorial by i
5. Store the result in factorial
6. Display the factorial value
7. End

Program:

num = int(input("Enter a positive number: "))

factorial = 1
for i in range(1, num + 1):
factorial = factorial * i

print("The factorial of", num, "is", factorial)

Result:

The program was executed successfully and the factorial of the given number was obtained.

Output:

Enter a positive number: 5


The factorial of 5 is 120

3. Write a Python program to check whether a given year is a leap year or not.

Aim

To write a Python program to determine whether a given year is a leap year.

Algorithm

1. Start
2. Input a year from the user
3. Check the condition:
o If the year is divisible by 4 and not divisible by 100
o OR the year is divisible by 400
4. If the condition is true, print "leap year"
5. Otherwise, print "not a leap year"
6. End

Program

year = int(input("Enter a 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")

Result
The program was executed successfully and the given year was checked whether it is a leap year or
not.

Output

Example 1:

Enter a year: 2024


2024 is a leap year

Example 2:

Enter a year: 2023


2023 is not a leap year

4. Write a Python program to display the multiplication table of a given number.

Aim

To write a Python program to display the multiplication table for a given number.

Algorithm

1. Start
2. Input a number from the user and store it in variable num
3. Display the message: "Multiplication table for num"
4. Initialize a counter variable i to 1
5. Repeat the following steps while i ≤ 10:
o Calculate product = num × i
o Display num x i = product
o Increment i by 1
6. End

Program

num = int(input("Enter a number to display its multiplication table: "))

print("Multiplication table for", num)

for i in range(1, 11):


print(num, "x", i, "=", num * i)

Result

The program was executed successfully and the multiplication table of the given number was displayed.

Output

Enter a number to display its multiplication table: 5


Multiplication table for 5
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

5. Write a Python program to display a right-angled triangle pattern using *.

Aim

To write a Python program to display a right-angled triangle pattern using *.

Algorithm

1. Start
2. Input the number of rows from the user
3. Use a loop from 1 to rows (outer loop)
4. For each row i, use another loop from 1 to i (inner loop)
5. Print * in each iteration of the inner loop
6. After each row, move to the next line
7. Repeat until all rows are printed
8. End

Program

rows = int(input("Enter the row size for the pattern: "))

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


for j in range(1, i + 1):
print("*", end="")
print()

Result

The program was executed successfully and the right-angled triangle pattern was displayed.

Output

Enter the row size for the pattern: 5


*
**
***
****
*****

6. Write a Python program to calculate the Simple Interest.

Aim

To write a Python program to calculate the Simple Interest for given principal, rate, and time.

Algorithm
1. Start
2. Input the principal amount (p)
3. Input the rate of interest (r)
4. Input the time in years (t)
5. Calculate simple interest using:
si = (p × r × t) / 100
6. Display the simple interest
7. End

Program

p = float(input("Enter principal amount: "))


r = float(input("Enter rate of interest: "))
t = float(input("Enter time in years: "))

si = (p * r * t) / 100

print("Simple Interest:", si)

Result

The program was executed successfully and the simple interest was calculated.

Output

Enter principal amount: 1000


Enter rate of interest: 5
Enter time in years: 2
Simple Interest: 100.0

7. Write a Python program to find the average of three numbers.

Aim

To write a Python program to calculate the average of three given numbers.

Algorithm

1. Start
2. Input the first number and store it in a
3. Input the second number and store it in b
4. Input the third number and store it in c
5. Calculate the average using:
average = (a + b + c) / 3
6. Display the average
7. Stop

Program

def average_3():
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

avg = (a + b + c) / 3
print("Average:", avg)

average_3()

Result

The program was executed successfully and the average of the three numbers was calculated.

🖥️ Output

Enter first number: 10


Enter second number: 20
Enter third number: 30
Average: 20.0

8. Write a Python program to determine the grade based on marks.

Aim

To write a Python program to assign a grade based on the marks obtained by a student.

Algorithm

1. Start
2. Input the marks from the user
3. Check the marks using conditions:
o If marks ≥ 90 → Print "A grade"
o Else if marks ≥ 80 → Print "B grade"
o Else if marks ≥ 70 → Print "C grade"
o Else if marks ≥ 60 → Print "D grade"
o Else if marks ≥ 50 → Print "You can do better"
o Else → Print "Need to work harder"
4. End

Program

marks = int(input("Enter your marks: "))

if marks >= 90:


print("A grade")
elif marks >= 80:
print("B grade")
elif marks >= 70:
print("C grade")
elif marks >= 60:
print("D grade")
elif marks >= 50:
print("You can do better")
else:
print("Need to work harder")

Result
The program was executed successfully and the grade was displayed based on the entered marks.

Output

Example 1:

Enter your marks: 92


A grade

Example 2:

Enter your marks: 65


D grade

Example 3:

Enter your marks: 45


Need to work harder

9. Write a Python program to concatenate two strings using the + operator.

Aim

To write a Python program to concatenate two strings using the + operator.

Algorithm

1. Start
2. Initialize a string variable str1 with value "WsCube"
3. Initialize another string variable str2 with value "Tech"
4. Concatenate str1, a space " ", and str2 using the + operator
5. Store the result in a variable result
6. Display the result
7. End

Program

str1 = "WsCube"
str2 = "Tech"

result = str1 + " " + str2 # Concatenation

print(result)

Result

The program was executed successfully and the two strings were concatenated.

Output

WsCube Tech

10. Write a Python program to find the length of a string (number of characters).

Aim
To write a Python program to calculate the length of characters in a string.

Algorithm

1. Start
2. Assign a string to a variable text
3. Use the len() function to find the length of the string
4. Store the result in a variable length
5. Display the length
6. End

Program

text = "Hello, World!"


length = len(text) # Finds number of characters

print(length)

Result

The program was executed successfully and the length of the string was calculated.

Output

13

11. Write a Python program to count the number of words in a sentence.


Aim
To write a Python program to count the number of words in a given sentence.
Algorithm
1. Start
2. Input a sentence from the user
3. Split the sentence into words using split()
4. Count the number of words using len()
5. Display the word count
6. Stop
Program
sentence = input("Enter a sentence: ")

words = [Link]()
count = len(words)

print("Number of words:", count)


Result
The program was executed successfully and the number of words in the sentence was counted.
Output
Enter a sentence: I like Python programming
Number of words: 4
12. Write a Python program to adding elements of two lists
Aim
To write a Python program to add corresponding elements of two lists and store the result in a new
list.
Algorithm
 Start
 Initialize two lists:
o list1 = [1, 2, 3]
o list2 = [4, 5, 6]
 Use zip() to combine elements of both lists index-wise
 Add corresponding elements using list comprehension
 Store the result in a new list called result
 Print the result
 Stop

Program
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = [x + y for x, y in zip(list1, list2)]
print(result)

Output
[5, 7, 9]

Result
The program successfully adds corresponding elements of two lists and displays the summed list
as output.

13. Write a Python program to check whether a number is Even or Odd.

Aim
To write a Python program to check whether a given number is even or odd.

Algorithm
1. Start
2. Input a number from the user and store it in a variable number
3. Check if number % 2 == 0
o If True → Display “Even number”
o Else → Display “Odd number”
4. End

Program
number = int(input("Enter a number: "))

if number % 2 == 0:
print(number, "is an even number")
else:
print(number, "is an odd number")
Output
Enter a number: 6
6 is an even number

(or)

Enter a number: 7
7 is an odd number

Result
Thus, the Python program to check whether a number is even or odd has been successfully executed.

14. Write a Python program to append an element to a list.


Aim
To write a Python program to add (append) a new element to an existing list.

Algorithm
1. Initialize the list numbers = [1, 2, 3, 4, 5]
2. Take input from the user
3. Convert input into integer using int()
4. Append the new number to the list using append()
5. Display the updated list

Program
numbers = [1, 2, 3, 4, 5]

new_number = int(input("Enter a number to add to the list: "))

[Link](new_number)

print("Updated list:", numbers)

Output
Enter a number to add to the list: 8
Updated list: [1, 2, 3, 4, 5, 8]

Result
Thus, the Python program to append an element to a list has been successfully executed.

15. Write a program to calculate mean, median and mode using Numpy.
Aim
To write a Python program to calculate mean, median and mode using Numpy
Algorithm
1. Start
2. Import NumPy and SciPy modules
3. Create a list of numbers
4. Calculate mean using [Link]()
5. Calculate median using [Link]()
6. Calculate mode using [Link]()
7. Display the results
8. Stop
Program
import numpy as np
from scipy import stats
data = [1, 2, 3, 4, 5, 5, 5]
mean = [Link](data)
median = [Link](data)
mode = [Link](data)[0]
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)
Output
Mean: 3.5714285714285716
Median: 4.0
Mode: 5
Result
The program successfully calculates the mean, median, and mode of the given data using NumPy
and SciPy.

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


Aim
To plot a line chart connecting the points (2, 5) and (9, 10) using the Matplotlib library in Python.

Algorithm
1. Start the program
2. Import [Link] module as plt
3. Define a list x with values [2, 9]
4. Define a list y with values [5, 10]
5. Use [Link](x, y) to plot the graph
6. Use [Link]() to display the graph
7. Stop the program

Program
import [Link] as plt

x = [2, 9]
y = [5, 10]
[Link](x, y)
[Link]()

Result
A line graph is displayed on the screen connecting the points (2, 5) and (9, 10).

Output
17. Write a program to display a scatter plot using the Matplotlib in Python.
Aim
To create a scatter plot using the Matplotlib library in Python.
Algorithm
1. Start the program
2. Import [Link] module as plt
3. Define a list x with values [2, 9, 8, 5, 6]
4. Define a list y with values [5, 10, 3, 7, 18]
5. Use [Link](x, y) to create a scatter plot
6. Use [Link]() to display the graph
7. Stop the program
Program
import [Link] as plt

x = [2, 9, 8, 5, 6]
y = [5, 10, 3, 7, 18]

[Link](x, y)
[Link]()
Result
A scatter plot is displayed on the screen showing points at:
 (2, 5)
 (9, 10)
 (8, 3)
 (5, 7)
 (6, 18)
Each point is plotted individually without connecting lines.

Output

18. Write a Python program to read data from a CSV file named "[Link]" and display the
first 10 rows using the Pandas library
Aim
To read data from a CSV file and display the first 10 rows using the Pandas library in Python.
Algorithm
1. Start the program
2. Import pandas module as pd
3. Specify the file path as "[Link]"
4. Use pd.read_csv() to read the CSV file into a DataFrame
5. Store the data in a variable data
6. Use [Link](10) to display the first 10 rows
7. Print the result
8. Stop the program
Program
import pandas as pd

file_path = "[Link]"
data = pd.read_csv(file_path)

print([Link](10))
Output
The first 10 rows of the CSV file [Link] will be displayed in tabular format (rows and columns).
Name, Age, Marks
John,20,85
Mary,21,90
Alex,19,78
David,22,88
Sophia,20,92
Daniel,23,75
Emma,21,89
Liam,20,84
Olivia,22,91
Noah,19,77
Result
The program successfully reads the CSV file and displays the first 10 rows of data.
19. Write a Python program to open and display an image file using the Pillow library.
Aim
To open and display an image file using the Pillow in Python.
Algorithm
1. Start the program
2. Import Image from PIL module
3. Specify the image file path as "[Link]"
4. Use [Link]() to open the image
5. Store the image in a variable
6. Use [Link]() to display the image
7. Stop the program
Program
from PIL import Image

image_path = "[Link]"
image = [Link](image_path)

[Link]()

Result
The program successfully opens and displays the image file [Link] on the screen using the default
image viewer.
Output
20. Write a Python program to open an image file and display its size using the Pillow library.
Aim
To open an image and find its dimensions (width and height) using the Pillow in Python.
Algorithm
1. Start the program
2. Import Image from PIL module
3. Specify the image file path as "[Link]"
4. Use [Link]() to open the image
5. Store the image in a variable
6. Use [Link] to get the dimensions of the image
7. Print the size
8. Stop the program
Program
from PIL import Image

image_path = "[Link]"
image = [Link](image_path)

print([Link])
Output
The output displays the size of the image in pixels as a tuple:
Example:
(800, 600)
 800 = width
 600 = height
Result
The program successfully opens the image file and displays its dimensions (width and height).

You might also like