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

Class 9 RecordBook 24 25

The document contains a series of Python programming exercises for Class 9 students, covering various topics such as printing patterns, calculating areas, and using input functions. Each section includes a specific aim and corresponding code examples to demonstrate the concepts. The exercises also involve list manipulation, arithmetic operations, and control structures like loops and conditionals.

Uploaded by

mdmalikahmed11
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)
19 views9 pages

Class 9 RecordBook 24 25

The document contains a series of Python programming exercises for Class 9 students, covering various topics such as printing patterns, calculating areas, and using input functions. Each section includes a specific aim and corresponding code examples to demonstrate the concepts. The exercises also involve list manipulation, arithmetic operations, and control structures like loops and conditionals.

Uploaded by

mdmalikahmed11
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

ARTIFICIAL INTELLIGENCE

RECORD WORK
CLASS 9
2024-25
1 PRINT() - USE ONLY PRINT FUNCTION
AIM:To print the following patterns using multiple print
commands-

Code:
# PRINTING PATTERN USING ONLY PRINT COMMAND
print("* * * * * *")
print("* * * * * *")
print("* * * * * *")
print("* * * * * *")
print("* * * * * *")

2 INPUT()- ACCEPT THE VALUES FROM THE USER

AIM: WRITE A PROGRAM TO CALCULATE AREA OF A TRIANGLEt THE


USER TO INPUT THE BASE AND HEIGHT OF A TRIANGLE AS INTEGERS.
Code:
b = int(input("Input the base : "))
h = int(input("Input the height : "))

# Calculate the area of the triangle using the formula: (base


* height) / 2.
area = b * h / 2
# Print the calculated area of the triangle.
print("area = ", area)

3 INPUT()- ACCEPT THE VALUES FROM THE USER

AIM: WRITE A PROGRAM TO FIND THE AVERAGE OF THE GIVEN 3


NUMBERS
Code:
a = int (input(" Please Enter the First Number: "))
b = int (input(" Please Enter the second number: "))
c = int (input(" Please Enter the third number: "))
average=(a+b+c)/3
print("The average of three numbers is ", average)

4. INPUT()- ACCEPT THE VALUES FROM THE USER

AIM: WRITE A PYTHON PROGRAM TO FIND VOLUME AND SURFACE AREA OF


CUBOID
Code:
length = float(input('Please Enter the Length of a Cuboid: '))
width = float(input('Please Enter the Width of a Cuboid: '))
height = float(input('Please Enter the Height of a Cuboid: '))

# Calculate the Surface Area


SA = 2 * (length * width + length * height + width * height)

# Calculate the Volume


Volume = length * width * height

# Calculate the Lateral Surface Area


LSA = 2 * height * (length + width)

print("\n The Surface Area of a Cuboid = " SA)


print(" The Volume of a Cuboid = " ,Volume);
print(" The Lateral Surface Area of a Cuboid = ",LSA)

5 INPUT()- ACCEPT THE VALUES FROM THE USER


AIM: Python Program to Convert Kilometer (km) to Meter (m)

Code:
# Python program to convert km to m

# Reading input
km = input("Enter distance in kilometer: ")

# Converting to float data type


km = float(km)

# Converting to meter
m = km * 1000;

# Displaying output
print("%0.3f Kilometer = %0.3f Meter" %(km,m))

6 INPUT()- ACCEPT THE VALUES FROM THE USER

AIM: WRITE A PROGRAM TO CALCULATE AREA AND A PERIMETER OF A


RECTANGLE
Code:
# Reading length from user
length = float(input("Enter length of the rectangle: "))

# Reading breadth from user


breadth = float(input("Enter breadth of the rectangle: "))

# Calculating area
area = length * breadth
# Calculating perimeter
perimeter = 2 * (length * breadth)

# Displaying results
print("Area of rectangle = ", area)
print("Perimeter of rectangle = ", perimeter)

7. AIM:WRITE A PROGRAM USING ALL ARITHMETIC OPERATORS AND


RELATIONS/COMPARISON OPERATORS.

num1=int(input("Enter first value="))


num2=int(input("Enter second value="))
#Adding
sum=num1+num2
print("The total is",sum)
#Subtraction
diff=num1-num2
print("The difference between two values is=",diff)
#Division
Quot=num1/num2
print("The quotient is=",Quot)
#Multiplication
prod=num1*num2
print("The product is=",prod)
#Floor division
FD=num1//num2
print("The rounded quotient is=",FD)
#Modulus
modu=num1*num2
print("The remainder is=",modu)
#Exponent
exp=num1**num2
print("The ans is=",exp)

#Relational or comparison operators


ans=num1==num2
print("Num1 is equal to num2=",ans)
ans=num1!=num2
print("Num1 is not equal to num2=",ans)
ans=num1>=num2
print("Num1 is greater than equal to num2=",ans)
ans=num1<num2
print("Num1 is less than num2=",ans)

#Logical Operators and, or, not


x=5
print(x>3 and x<10)
y=8
print(y<8 or y<7)
z=9
print(not(x>3 and x<10)
print(not(x>3 or x<10

8. Aim:Create list

# WORKING WITH LISTS


#Positive indexing
fruits=['apple','kiwi','orange']
print(fruits[1])

#Negative indexing
fruits=['apple','kiwi','orange']
print(fruits[-1])

#Range of indexes
fruits=['apple','kiwi','orange','melon','mango','banana']
print(fruits[2:5])

fruits=['apple','kiwi','orange','melon','mango','banana']
print(fruits[-4:-1])
#Replace element in the list
days=['saturday','sunday','monday']
days[2]='holiday'
print(days)

#Find List Length


days=['saturday','sunday','monday']
print(len(days))

9. AIM:WRITE PYTHON PROGRAMS USING METHODS INSERT, APPEND,


SORT,REVERSE,POP,REMOVE

# List methods:

#append()- add an element at the end


fruits=['apple','kiwi','orange','melon','mango','banana']
fruits.append('grapes')
print("add an element at the end")
print(fruits)
print("____________________________________________________")

#insert()- add an elemeny at specified location


fruits=['apple','kiwi','orange','melon','mango','banana']
fruits.insert(1,'dragon_fruit')
print("add an elemeny at specified location")
print(fruits)
print("____________________________________________________")

#remove()- removes the item or element with the specified value


fruits=['apple','kiwi','orange','melon','mango','banana']
fruits.remove('banana')
print("removes the item or element with the specified value")
print(fruits)
print("_____________________________________________________")

#pop()- Removes the element from the specified location


fruits=['apple','kiwi','orange','melon','mango','banana']
fruits.pop(1)
print("Removes the element from the specified location")
print(fruits)
print("_____________________________________________________")

#sort()- sort the data in ascending order


numbers=[4,2,45,23,87]
numbers.sort()
print("Ascending order")
print(numbers)
print("______________________________________________________"
)

#reverse - Reverse the order of the list


numbers=[4,2,45,23,87]
numbers.reverse()
print("Descending order or reverse the order")
print(numbers)
print("______________________________________________________"
)
10 AIM:Python program to print all the even numbers within the given range.

# if the given range is 10

given_range = 10

for i in range(given_range):
# if number is divisble by 2
# then it's even

if i%2==0:
# if above condition is true
# print the number
print(i)
11 Aim: write a program to find the given number is even or odd
# if the given range is 10
i=int(input("enter any number="))
if i%2==0:
print("Even number=",i)
else:
print("odd number")

12 Aim: Write a program to check if the number is positive,


negative or zero
num=float(input(“Enter any number=”))
If (num>=0):
if(num==0):
print(“Zero”)
else:
print(“Positive number”)
else:
print(“Negative”)

13 Aim: Write a program using for loop range function

#The range() function returns a sequence of numbers, starting


from 0
for x in range(6):
print(x)
14 Aim: Using for loop print pattern pyramid
#Outer for loop to handle number of rows
for i in range(0, rows):
#Inner for loop to handle number of columns
#values change according to the outer loop
for j in range(0, i + 1):
print("* ", end=" ")

#End line after each row


print()

15 Aim: Print multiplication table for any given number


# Multiplication table (from 1 to 10) in Python

num = 12

# To take input from the user


# num = int(input("Display multiplication table of? "))

# Iterate 10 times from i = 1 to 10


for i in range(1, 11):
print(num, 'x', i, '=', num*i)

You might also like