0% found this document useful (0 votes)
6 views4 pages

Class 9 - Python Programs

The document contains a series of Python programs designed for Class IX students, covering various topics such as calculating areas of shapes, simple interest, arithmetic operations, type conversion, and conditional statements. Each program includes user input prompts and outputs the results based on the calculations or conditions specified. The programs aim to enhance students' understanding of basic programming concepts and logic in Python.

Uploaded by

navink2
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)
6 views4 pages

Class 9 - Python Programs

The document contains a series of Python programs designed for Class IX students, covering various topics such as calculating areas of shapes, simple interest, arithmetic operations, type conversion, and conditional statements. Each program includes user input prompts and outputs the results based on the calculations or conditions specified. The programs aim to enhance students' understanding of basic programming concepts and logic in Python.

Uploaded by

navink2
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

CLASS IX

Python Programs

Program 1. WAP to calculate area of area of a circle.


Solution:
r = float(input("Enter the radius of the circle: "))
pi= 3.14
area= pi * r ** 2
print(“The area of the circle is: ", area)

Program 2. WAP to calculate area of a rectangle.


Solution:
l = float(input("Enter the length of the rectangle: "))
b = float(input("Enter the breadth of the rectangle: "))
area= l*b
print("The area of the rectangle is: ", area)

Program 3. WAP to calculate simple interest by accepting the value of principal, rate and
time from users.
Solution:
p = float(input("Enter the Principal amount: "))
r = float(input("Enter the Rate of interest : "))
t = float(input("Enter the Time in years: "))
SI = (p * r * t) / 100
print("Simple Interest = ", SI)

Program 4. WAP to calculate perform arithmetic operations on variables.


Solution:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
addition = num1 + num2
subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2
modulus = num1 % num2
floor_division = num1 // num2
print("Arithmetic Operations:")
print("Addition: ", addition)
print("Subtraction: ", subtraction)
print("Multiplication: ", multiplication)
print("Division: ", division)
print("Modulus: ", modulus)
print("Floor_Division: ", floor_division)

Program 5. WAP to convert the data type of the following variable as given
a = “10010” # into integer
b = 21.684 # into integer
c = 5460 # into float
DOB = 06052010 # into str
Solution:
a_int = int(a) # string → integer
b_int = int(b) # float → integer
c_float = float(c) # int → float
DOB_str = str(DOB) # int → string
print("a : ", a_int, type(a_int))
print("b : ", b_int, type(b_int)) print("c
: ", c_float, type(c_float))
print("DOB : ", DOB_str, type(DOB_str))
Program 6 →
WAP to check whether the given number is positive integer or negative integer.
num = float(input("Enter a number: "))
if num > 0:
print("The number is a positive integer.")
elif num < 0:
print("The number is a negative integer.")
else:
print("The number is zero (neither positive nor negative).")

Program 7 →
WAP to check if a number is odd or even using if-else.
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num," is even.")
else:
print(num," is odd.")

Program 8 →
Write a program to check if a person can vole (check if age is greater or equal
to 18) accept the age from user.
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

Program 9 →
Write a program to check age criteria:
I) 0-12 - “Kid”
II) 12-19 - “teenager”
III) 20-30 - “young”
IV) 30-45 - “mature”
V) 45-60 - “Experience”
VI) 60-75 - “old”
VII) 75 above - “senior citizen”
age = int(input("Enter your age: "))
if age <= 12:
category = "Kid"
elif age <= 19:
category = "teenager"
elif age <= 30:
category = "young"
elif age <= 45:
category = "mature"
elif age <= 60:
category = "Experience"
elif age <= 75:
category = "old"
else:
category = "senior citizen"
print("Based on your age, you are categorized as:",category)

Program 10→
WAP to find greatest of three numbers using if-elif -else

a = float(input("Enter first number: "))


b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
if a > b and a > c:
greatest = a
elif b > c:
greatest = b
else:
greatest = c
print(“The greatest number is: ", greatest)

You might also like