Here are a few basic Python programs suitable for Class IX students:
1. Program to Print "Hello, World!"
print("Hello, World!")
2. Program to Add Two Numbers
# Input two numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
# Add the numbers
sum = num1 + num2
# Display the result
print("The sum of", num1, "and", num2, "is", sum)
3. Program to Find the Square of a Number
# Input a number
num = int(input("Enter a number: "))
# Calculate the square
square = num ** 2
# Display the result
print("The square of", num, "is", square)
4. Program to Find the Area of a Circle
# Input the radius
radius = float(input("Enter the radius of the circle: "))
# Calculate the area
area = 3.14 * radius * radius
# Display the result
print("The area of the circle is", area)
Here are some basic Python programs to calculate the area of different 2D figures, suitable for Class IX:
1. Area of a Rectangle
# Input the length and width of the rectangle
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
# Calculate the area
area = length * width
# Display the result
print("The area of the rectangle is", area)
2. Area of a Square
# Input the side length of the square
side = float(input("Enter the side length of the square: "))
# Calculate the area
area = side * side
# Display the result
print("The area of the square is", area)
3. Area of a Triangle
# Input the base and height of the triangle
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
# Calculate the area
area = 0.5 * base * height
# Display the result
print("The area of the triangle is", area)
4. Area of a Circle
# Input the radius of the circle
radius = float(input("Enter the radius of the circle: "))
# Calculate the area
area = 3.14 * radius * radius
# Display the result
print("The area of the circle is", area)
5. Area of a Parallelogram
# Input the base and height of the parallelogram
base = float(input("Enter the base of the parallelogram: "))
height = float(input("Enter the height of the parallelogram: "))
# Calculate the area
area = base * height
# Display the result
print("The area of the parallelogram is", area)
6. Area of a Trapezium
python
# Input the lengths of the parallel sides and the height
side1 = float(input("Enter the length of the first parallel side: "))
side2 = float(input("Enter the length of the second parallel side: "))
height = float(input("Enter the height of the trapezium: "))
# Calculate the area
area = 0.5 * (side1 + side2) * height
# Display the result
print("The area of the trapezium is", area)
0 Comments
Please do note create link post in comment section