0% found this document useful (0 votes)
207 views3 pages

Class 9 AI Python Practical Exercises

IX_AI_Python Practical List – I_Solutions
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)
207 views3 pages

Class 9 AI Python Practical Exercises

IX_AI_Python Practical List – I_Solutions
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

- Work ASTER PUBLIC SCHOOL, KP-5, GREATER NOIDA WEST

Part B
Worksheet – Python Practical List – I Class: IX (AI)

1. Take a string “Morning “and the float value “90.4” and try and both of them by using the float() function
Code:
string_value = "Morning"
float_value = 90.4

# Trying to convert string to float (this will cause an error)


try:
converted_string = float(string_value)
except ValueError:
print(f"Cannot convert '{string_value}' to a float.")

# Converting float to float (redundant, but shown for understanding)


converted_float = float(float_value)

print("Converted Float Value:", converted_float)

2. Write a program to calculate the surface area and volume of a cuboid.


Code : # Dimensions of the cuboid
length = 5
width = 3
height = 4

# Calculate surface area


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

# Calculate volume
volume = length * width * height
print("Surface Area of Cuboid:", surface_area)
print("Volume of Cuboid:", volume)

3. Write a program to check whether the given number is even or odd.


Code :
number = 7

# Check if the number is even or odd


if number % 2 == 0:
print(f"{number} is Even.")
else:
print(f"{number} is Odd.")

4. Write a program to print number from 1-10 using range(n) function.


Code:
# Using range to print numbers from 1 to 10
for i in range(1, 11):
print(i)
5. Write a program to delete an element from a list.
Sub=[‘English’, ‘Hindi’, ‘Math’, ‘Science’, French’]

Code:
# List of subjects
subjects = ['English', 'Hindi', 'Math', 'Science', 'French']

# Delete the third element ('Math')


del subjects[2]

print("Updated List of Subjects:", subjects)

6. Write a program to perform arithmetical operations with menu option .


Example :
Select the option
1. Addition
2. Subtraction
3. Multiplication
4. Division
# User input for numbers
num1 = 10
num2 = 5

# Display menu
print("Select the operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")

# Input choice
choice = 1 # Example choice for addition

# Perform operations based on user choice


if choice == 1:
result = num1 + num2
print(f"Addition Result: {result}")
elif choice == 2:
result = num1 - num2
print(f"Subtraction Result: {result}")
elif choice == 3:
result = num1 * num2
print(f"Multiplication Result: {result}")
elif choice == 4:
result = num1 / num2
print(f"Division Result: {result}")
else:
print("Invalid choice!")
10

You might also like