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

Practical File Class 9

This document is a practical file for a class IX-A student at KR Mangalam World School, Gurugram, focusing on various Python programming exercises. It includes a list of programs that cover mathematical calculations, list operations, and control statements. Each program is presented with input and output examples, demonstrating the application of Python in solving practical problems.

Uploaded by

rajvirarora9211
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)
4 views

Practical File Class 9

This document is a practical file for a class IX-A student at KR Mangalam World School, Gurugram, focusing on various Python programming exercises. It includes a list of programs that cover mathematical calculations, list operations, and control statements. Each program is presented with input and output examples, demonstrating the application of Python in solving practical problems.

Uploaded by

rajvirarora9211
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/ 18

KR MANGALAM WORLD SCHOOL, GURUGRAM

ARTIFICIAL INTELLIGENCE

PRACTICAL FILE

SESSION: 2024-25

Roll no : 20

Name : Naitik Gupta

Class : IX-A

Submitted to : Ms. Shelly Arora


INDEX
S.NO. PROGRAMS PAGE NO.

1. Program to find square of number 7.

2. Program to convert length given in kilometres into meters.


Program to calculate simple interest if the Principle Amount = 2000,
3.
Rate_of_interest = 4.5 and Time = 10.
4. Program to calculate area and parimeter of a rectangle.

5. Program to calculate area of a triangle with Base and Height.

6. Program to calculate average marks of 3 subjects.

7. Program to calculate surface area and volume of a Cuboid.


Program to make calculator (use all arithmetic operators +,-,*,/,//,%,**) using if-
8.
elif- else statement
9. Program to print grade according to the marks entered by the user: (use if-elif-else
statement)
A: 90 and above
A+: between 80 and 89
B: between 70 and 79
B+: between 60 and 69
C: between 50 and 59
D : below 50
10. Program to display 1 to 50 natural numbers.
11. Program to print characters of your name.

12. Program to print odd numbers from 1 to 100 in reverse order using for loop.

13. Program to print table of a number. (take number from user)

14. Program to display sum of even numbers from 1 to 100.

15. Program to display sum of odd numbers from 1 to 100.


16. Program to perform to perform following list operations using list functions on the
given list
a=[23,54,11,78,90,32,10,26]:
i) Insert 15 at 4th position
ii) Add element 100 at the end of the list
iii) Add the list [7,21,35] in the list a.
iv) Display list in descending order
v) Remove the element 90 from the list
vi) Display the length of the list
vii) Delete last element of a list.
viii) Print largest element and smallest element of the list
ix) Write the output of :
print(a[3:7])
Class 9 Python Programs

1. Program to find the square of the


number 7.
Input:
number = 7
square = number ** 2
print('The square of', number, 'is', square)
Output:

2.
Program to convert length given in
kilometers into meters.
Input:
kilometres = float(input('Enter length in
kilometres: '))
meters = kilometres * 1000
print('Length in meters:', meters)
Output:
3. Program to calculate simple interest if
the Principle Amount = 2000, Rate of
interest = 4.5 and Time = 10.
Input:
p = 2000
r = 4.5
t = 10
si = (P * R * T) / 100
print("The Principle Amount is rs.", p)
print("The Rate of Interest per annum is", r, "%")
print("The Time is", 10, "years")
print("The Simple Interest is rs.", si)

Output:
4. Program to calculate the area and
perimeter of a rectangle.
Input:
length = float(input('Enter length of rectangle: '))
breadth = float(input('Enter breadth of
rectangle:'))
area = length * breadth
perimeter = 2 * (length + breadth)
print('Area:', area)
print('Perimeter:', perimeter)
Output:

5. Program to calculate area of a triangle


with Base and Height.
Input:
base = float(input('Enter base of triangle: '))
height = float(input('Enter height of triangle: '))
area = 0.5 * base * height
print('Area of triangle:', area)
Output:

6. Program to calculate average marks of 3


subjects.
Input:
marks1 = float(input('Enter marks of subject 1:
'))
marks2 = float(input('Enter marks of subject 2:
'))
marks3 = float(input('Enter marks of subject 3:
'))
average = (marks1 + marks2 + marks3) / 3
print('Average marks:', average)
Output:
7. Program to calculate surface area and
volume of a Cuboid.
Input:
length = float(input('Enter length of cuboid: '))
breadth = float(input('Enter breadth of cuboid: '))
height = float(input('Enter height of cuboid: '))
surface_area = 2 * (length * breadth + length *
height + breadth * height)
volume = length * breadth * height
print('Surface area:', surface_area)
print('Volume:', volume)
Output:

8. Program to make calculator (use all


arithmetic operators +,-,*,/,//,%,**) using if-
elif-else statement
Input:
num1 = float(input('Enter first number: '))
num2 = float(input('Enter second number: '))
operation = input('Enter operation (+,-,*,/,//,
%,**): ')
if operation == '+':
print('Result:', num1 + num2)
elif operation == '-':
print('Result:', num1 - num2)
elif operation == '*':
print('Result:', num1 * num2)
elif operation == '/':
print('Result:', num1 / num2)
elif operation == '//':
print('Result:', num1 // num2)
elif operation == '%':
print('Result:', num1 % num2)
elif operation == '**':
print('Result:', num1 ** num2)
else:
print('Invalid operation')
Output:

9. Program to print grade according to the


marks entered by the user: (use if-elif-else
statement)
Input:
marks = float(input('Enter marks (out of 100): '))
if marks >= 90:
print('Grade: A')
elif marks >= 80:
print('Grade: A+')
elif marks >= 70:
print('Grade: B')
elif marks >= 60:
print('Grade: B+')
elif marks >= 50:
print('Grade: C')
else:
print('Grade: D')
Output:
10. Program to display 1 to 50 natural
numbers.
Input:
for num in range(1, 51):
print(num)

Output:
11. Program to print characters of your
name.
Input:
name = str(input('Enter Your Name: '))
for char in name:
print(char)

Output:
12. Program to print odd numbers from 1 to
100 in reverse order using for loop.

Input:for num in range(99, 0, -2):


print(num)
Output:
13. Program to print table of a number.
(take number from user)
Input:
num = int(input('Enter a number: '))
for i in range(1, 11):
print(f'{num} * {i} = {num*i}')
Output:
14. Program to display sum of even
numbers from 1 to 100.
Input:
sum_even = 0
for num in range(2, 101, 2):
sum_even += num
print('Sum of all even numbers m 1 100 are',
sum_even)
Output:
15. Program to display sum of odd numbers

from 1 to 100.
Input:
sum_odd = 0
for num in range(1, 101, 2):
sum_odd += num
print('Sum of odd numbers:', sum_odd)
Output:
16.

Program to perform the following list


operations using list functions on the given
list
Input:
# Initial list
a = [23, 54, 11, 78, 90, 32, 10, 26]

# i) Insert 15 at 4th position


a.insert(3, 15) # Insert 15 at index 3 (4th
position)
print("After inserting 15 at 4th position:", a)

# ii) Add element 100 at the end of the list


a.append(100) # Add 100 to the end of the list
print("After adding 100 at the end:", a)

# iii) Add the list [7, 21, 35] in the list a


a.extend([7, 21, 35]) # Add elements of the list
[7, 21, 35] to 'a'
print("After adding [7, 21, 35] to the list:", a)

# iv) Display list in descending order


a.sort(reverse=True) # Sort the list in
descending order
print("List in descending order:", a)
# v) Remove the element 90 from the list
a.remove(90) # Remove element 90 from the
list
print("After removing 90 from the list:", a)
# vi) Display the length of the list
length = len(a) # Get the length of the list
print("Length of the list:", length)
# vii) Delete last element of the list
del a[-1] # Delete the last element
print("After deleting the last element:", a)
# viii) Print largest and smallest element of the
list
largest = max(a) # Find the largest element
smallest = min(a) # Find the smallest element
print("Largest element:", largest)
print("Smallest element:", smallest)
# ix) Write the output of: print(a[3:7])
print("Output of a[3:7]:", a[3:7]) # Slicing the list
from index 3 to 6
Output:

You might also like