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

IX PYTHON PRACTICAL FILE

The document contains a series of Python practical programs for Class IX, covering various topics such as arithmetic operations, calculating area and perimeter, converting units, and string operations. Each program includes sample code, expected output, and confirms successful execution. The programs aim to enhance students' understanding of Python programming through practical applications.

Uploaded by

areebwais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

IX PYTHON PRACTICAL FILE

The document contains a series of Python practical programs for Class IX, covering various topics such as arithmetic operations, calculating area and perimeter, converting units, and string operations. Each program includes sample code, expected output, and confirms successful execution. The programs aim to enhance students' understanding of Python programming through practical applications.

Uploaded by

areebwais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

ACADEMIC YEAR 24-25

PYTHON PRACTICAL PROGRAMS


CLASS IX

# 1. To find the square of number


n=int(input("Enter any number"))
square= n * n
print (" The square value of n is",square)

Output:
Enter any number 6
The square value of n is 36

Result: Thus the above program has been executed successfully.

# 2. To Perform Arithmetic Operations:


a=int(input("Enter first number"))
b=int(input("Enter second number"))
s= a+b
M= a*b
d= a/b
fl=a//b
r=a%b
p=a ** b
print(" The Sum is",s)
print(" The Multiply is",M)
print(" The Division is",d)
print(" The floor division is",fl)
print(" The remainder is",r)
print(" The power is",p)

Output:
Enter first number 4
Enter second number 2
The Sum is 6
The Multiply is 8
The Division is 2.0
The floor division is 2
The remainder is 0
The power is 16

Result: Thus the above program has been executed successfully.


# 3.To print the table of 10 terms
n= int(input("No of Terms"))
for i in range(1,n):
print (n,"x",i,"=", n*i)

Output:
No of Terms 6
6x1=6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30

Result: Thus the above program has been executed successfully.

#4. To calculate Simple interest:


amount = float(input("Principal Amount"))
time = int(input("Duration"))
rate = float(input("Interest Rate"))
simple_interest = (amount * time * rate) / 100
print("Total interest you have to pay: ", simple_interest)

Output:
Principal Amount 50000
Duration 3
Interest Rate 3
Total interest you have to pay: 4500.0

Result: Thus the above program has been executed successfully.

#5. To convert given kilometer into Meter


km = float(input("Enter distance in kilometer: "))
m = km * 1000;
print ("%0.3f Kilometer = %0.3f Meter" %(km,m))

Output:
Enter distance in kilometer: 12
12.000 Kilometer = 12000.000 Meter

Result: Thus the above program has been executed successfully.


#6. To Find Area and Perimeter of a Rectangle
length = int(input('Length : '))
width = int(input('Width : '))
area = length * width
perimeter= 2 * (length + width)
print (“Area of the Rectangle:”, area)
print (“Perimeter of the Rectangle : “,perimeter)

Output:
Length : 8
Width : 5
Area of the Rectangle: 40
Perimeter of the Rectangle : 26

Result: Thus the above program has been executed successfully.

# 7. To calculate Area of a triangle with Base and Height


base = float (input ('Please Enter the Base of a Triangle: '))
height = float (input ('Please Enter the Height of a Triangle: '))
# calculate the area
area = (base * height) / 2
print ("The Area of a Triangle using", base, "and", height, " = ", area)

Output:
Please Enter the Base of a Triangle: 7
Please Enter the Height of a Triangle: 6
The Area of a Triangle using 7.0 and 6.0 = 21.0

Result: Thus the above program has been executed successfully.


# 8. Python Program to Calculate Total Marks Percentage and Grade of a Student
print ("Enter the marks of five subjects::")
s1 = int (input ("Enter subject1 Mark"))
s2 = int (input ("Enter subject2 Mark"))
s3 = int (input ("Enter subject3 Mark"))
s4 = int (input ("Enter subject4 Mark"))
s5 = int (input ("Enter subject5 Mark"))
total, average, percentage, grade = None, None, None, None
total = s1 + s2 + s3 + s4 + s5
average = total / 5.0
percentage = (total / 500.0) * 100
if average >= 90:
grade = 'A'
elif average >= 80 and average < 90:
grade = 'B'
elif average >= 70 and average < 80:
grade = 'C'
elif average >= 60 and average < 70:
grade = 'D'
else:
grade = 'E'
print ("\nThe Total marks is: \t", total, "/ 500.00")
print ("\nThe Average marks is: \t", average)
print ("\nThe Percentage is: \t", percentage, "%")
print ("\nThe Grade is: \t", grade)

Output:
Enter the marks of five subjects:
Enter subject1 Mark 89
Enter subject2 Mark 87
Enter subject3 Mark 76
Enter subject4 Mark 98
Enter subject5 Mark 90
The Total marks is: 440 / 500.00
The Average marks is: 88.0
The Percentage is: 88.0 %
The Grade is: B

Result: Thus the above program has been executed successfully.


# 9. Python program to find the largest number among the three input numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)

Output:
Enter first number: 8
Enter second number: 9
Enter third number: 10
The largest number is 10.0

Result: Thus the above program has been executed successfully.

# 10 To Check if a Number is Positive, Negative or 0


num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")

Output:
Enter a number: 8
Positive number
Enter a number: -7
Negative number

Result: Thus the above program has been executed successfully.


# 11. Python program to find the factorial of a number provided by the user.
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)

Output:
Enter a number: 5
The factorial of 5 is 120

Result: Thus the above program has been executed successfully.

12. # Python program for String Functions:


s = "Strings are awesome!"
# Length should be 20
print("Length of s = %d",len(s))

# First occurrence of "a" should be at index 8


print("The first occurrence of the letter a = %d", s.index("a"))

# Number of a's should be 2


print("a occurs %d times" , s.count("a"))

# Slicing the string into bits


print("The first five characters are %s”, s[:5]) # Start to 5
print("The next five characters are '%s'" , s[5:10]) # 5 to 10
print("The thirteenth character is '%s'" , s[12]) # Just number 12
print("The characters with odd index are '%s'" ,s[1::2]) #(0-based indexing)
print("The last five characters are '%s'" , s[-5:]) # 5th-from-last to end

# Convert everything to uppercase


print("String in uppercase: %s" , s.upper())

# Convert everything to lowercase


print("String in lowercase: %s" , s.lower())
# Check how a string starts and ends
s="welcome to python"
s.startswith("wel")
print(s)
s.endswith("on")
print(s)

# Split the string into three separate strings, each containing only a word
print("Split the words of the string: %s" % s.split(" "))

Output:

Length of s = 20
The first occurrence of the letter a = 8
a occurs 2 times
The first five characters are 'Strin'
The next five characters are 'gs ar'
The thirteenth character is 'a'
The characters with odd index are 'tig r wsm!'
The last five characters are 'some!'
String in uppercase: STRINGS ARE AWESOME!
String in lowercase: strings are awesome!
welcome to python
welcome to python
Split the words of the string: ['welcome', 'to', 'python']

Result: Thus the above program has been executed successfully.

# 13. Python program for String operations:


str1 = "Hello, world!" # compare str1 and str2
str2 = "I love Swift."
str3 = "Hello, world!"
print(str1 == str2)
print(str1 == str3)
greet = "Hello" # join string using + operator
name = "Jack"
result = greet+name
print(result)
result1= greet*5 # Copy/Replication of string using * operator.
print(result1)
for letter in greet: # iterating through greet string
print(letter)
print(len(greet)) # count length of greet string
print('a' in 'program') # String Membership
print('at' not in 'battle')
Output:
False
True
HelloJack
HelloHelloHelloHelloHello
H
e
l
l
o
5
True
False
Result: Thus the above program has been executed successfully.

14. # Python program for List operations:


list1 = [11, 5, 17, 18, 23]
print(list1)
print(list1[2])
print(list1[4])
print (list1[: :])
print(list1[: :-1])
print(list1[-2])
print(list1[-2])

list1.append(9) #Append an element to the list


print(list1[: :])

print( “The Length of List”, len(list1)) # Length of the list


for ele in range(0, len(list1)):
total = total + list1[ele]
print("Sum of all elements in given list: ", total)

L.pop() #Deleting last element from a list


print (L)

list3=["one",8,10,"three"]
list4=["two","five",3.5,2]
list3.extend(list4) #Extend the list
print(list1)

print(max(list1)
print(max(list1)

Output:

[11, 5, 17, 18, 23]


17
23
[11, 5, 17, 18, 23]
[23, 18, 17, 5, 11]
18
5
[11, 5, 17, 18, 23, 9]
The Length of List 6
Sum of all elements in given list: 83
[11, 5, 17, 18, 23]
['one', 8, 10, 'three', 'two', 'five', 3.5, 2]
23
5

Result: Thus the above program has been executed successfully.

You might also like