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

Class 10 Practicles

Uploaded by

Vandana Barai
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 views9 pages

Class 10 Practicles

Uploaded by

Vandana Barai
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

VEDIKA BARAI

Class 10 Python Practicals

Practical 1

Aim: Write a Python program to print a "Hello" message.

Code

print("Hello, welcome to Python programming")

Sample Output

Hello, welcome to Python programming

Result: Message printed successfully

Practical 2

Aim: Write a Python program to obtain length and breadth of a rectangle and calculate its area.

Code:

1- float(input("Enter length: "))

b= float(input("Enter breadth: "))

area 1 b

print("Area of rectangle:", area)

Sample Output:

Enter length: 5

Enter breadth: 4

Area of rectangle: 20.0

Result: Rectangle area calculated.

Practical 3

Aim: Write a Python program to obtain 3 numbers and print their sum Code:

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

b= int(input("Enter second number: "))

c=int(input("Enter third number: ")) print("Sum =", a+b+c)

Sample Output:

Enter first number: 2

Enter second number: 3

Enter third number: 5

Sum = 10
Result: Sum of 3 numbers displayed.

Practical 4

Aim: Write a Python program to input two numbers and swap them. Code:

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

bint(input("Enter second number: "))

a, b-b, a

print("After swapping a", a "b", b) Sample Output:

Enter first number: 4

Enter second number: 7

After swapping a-7b-4

Result: Numbers swapped correctly.

Practical S

Aim

Write a Python program to convert temperature from Celsius to Fahrenheit. Also write the program to convert
Fahrenheit to Celsius.

Formula:

"I

Code:

F C 9/5+ 32 (Celsius to Fahrenheit) C=(F-32) x 5/9 (Fahrenheit to Celsius)

(a) Celsius to Fahrenheit Conversion

#Input temperature in Celsius

celsius = float(input("Enter temperature in Celsius:"}}

# Convert to Fahrenheit

fahrenheit (celsius 9/5)+32

#Output the result

print("Temperature in Fahrenheit:", fahrenheit) Enter temperature in Celsius: 25

Temperature in Fahrenheit: 77.0

b) Fahrenheit to Celsius Conversion

# Input temperature in Fahrenheit

fahrenheit = float(input("Enter temperature in Fahrenheit: "))

# Convert to Celsius

celsius = (fahrenheit-32) 5/9


# Output the result

print("Temperature in Celsius:", celsius) Sample Output:

Enter temperature in Fahrenheit: 98.6

Temperature in Celsius: 37.0

Practical 6

Aim: Write a Python program to input two numbers and check whether they are equal.

Code:

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

b = int(input("Enter second number: "))

if a == b:

print("Numbers are equal")

else:

print("Numbers are not equal") Sample Output:

Enter first number: 10

Enter second number: 20

Numbers are not equal

Result: Equality checked correctly.

Practical 7

Aim: Write a Python program to input a number and check if it is odd or even. Code:

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

if num % 2 == 0:

else:

print("Even")

print("Odd")

Sample Output:

Enter a number: 9

Odd

Result: Odd or even identified.

Practical 8

Aim: Write a Python program to check if a number is greater than 100.

Code:
num int(input("Enter a number:"))

if num> 100:

print("Number is greater than 100")

else:

print("Number is not greater than 100") Sample Output:

Enter a number: 150

Number is greater than 100

Result: Correctly checked greater than 100.

Practical 9

Aim: Write a Python program to print all items from a list containing colour names.

Code:

colors = ["Red", "Green", "Blue", "Yellow"]

for color in colors:

print(color)

Sample Output:

Red

Green

Blue

Yellow

Result: All colors printed from list.

Practical 10

Aim: Write a Python program to compute total marks and percentage from a list of subject marks.

Code:

# Input: Number of subjects

n = int(input("Enter number of subjects: "))

# Input: Marks for each subject

marks = []

for i in range(n):

m = float(input(f'Enter marks for subject (i+1): "))

marks.append(m)

# Calculate total and percentage

total sum(marks)
percentage (total /(n* 100)) 100 # assuming each subject is out of 100

#Output the results

print("Total Marks:", total)

print("Percentage", percentage, "%")

Sample Output:

Enter number of subjects: 5

Enter marks for subject 1: 78

Enter marks for subject 2: 85 Enter marks for subject 3:92 Enter marks for subject 4: 88 Enter marks for subject
5: 76 Total Marks: 419.0 Percentage: 83.8%

Practical 17

Aim: Write a Python program to input a number and print its reverse. Code:

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

rev = 0

while num> 0:

rev = rev

num // 10

10+ num % 10

print("Reversed number:", rev)

Sample Output:

Enter a number: 123

Reversed number: 321

Result: Number reversed correctly.

Practical 18

Aim: Write a Python program to check whether a 3-digit number is an Armstrong number. Armstrong number is
one that is equal to sum of the cubes of its digits.

153=1+5+33=1+125+27=153

Code:

num = int(input("Enter a 3-digit number: "))

temp = num

sum=0

while num> 0:

digit- num % 10
sum digit 3

num // 10

if temp sum:

print("Armstrong number")

else

print("Not Armstrong")

Sample Output:

Enter a 3-digit number: 153

Armstrong number

Result Armstrong number verified.

Practical 11

Aim: Write a Python program to print the multiplication table of 7.

Code

for i in range(1, 11) print(7x170)

Sample Output

7x1=7

7x2-14

7x3-21

7x4-28

7x5-35

786=42

7x7-49

7x8-56

7x9-63

7x10-70

Result: Table of 7 printed.

Practical 12

Aim Write a Python program to check whether a year is a leap year or not. Code:

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

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

print("Leap Year")
else:

print("Not a Leap Year")

Sample Output:

Enter a year: 2024

Leap Year

Result: Leap year checked correctly

Practical 13

Aim: Write a Python program to check number is even and ≤50, even and 50, even and >50 or o Code:

#Input a number from user

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

#Check if number is even or odd and its value range

if num % 2 0:

if num < 50:

print("Even and < 50")

elif num 50:

ele

print("Even and 50")

print("Even and 50")

else:

print("Odd")

Sample Output

Enter a number 36

Even and 50

Result Even/odd and condition checked

Practical 14

Aim: Write a Python program to print squares of all numbers in the list 18.2.7,11,20,61

Aim:

To iterate over a list of numbers and print the square of each element

This program helps understand list traversal and use of the exponentiation operator ("").

Code:

#List of numbers

1st =
[8, 2, 7, 11, 20, 6]

#Loop through each number and print its square

for i in Ist:

print(), "squared is", 12)

Sample Output:

8 squared is 64

2 squared is 4

7 squared is 49 11 squared is 121 20 squared is 400 6 squared is 36

Practical 15

Aim: Write a Python program to print numbers divisible by 5 from a list. numbers = [11, 25, 35, 26, 50, 61]

Code:

# List of numbers

numbers = [11, 25, 35, 26, 50, 61]

# Print numbers divisible by 5 print("Numbers divisible by 5 are:") for num in numbers:

if num % 5 == 0: print(num)

Sample Output:

Numbers divisible by 5 are:

25

35

50

Result: Divisible by 5 numbers printed.

Practical 16

Aim: Write a Python program to input a number and print the sum of its digits.

Code:

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

sum=0

while num> 0:

sum+ num % 10

num // 10

print("Sum of digits:", sum)

Sample Output:

Enter a number: 123


Sum of digits: 6

Result: Digit sum calculated.

You might also like