CLASS 9 PYTHON

 Basic Input & Arithmetic Operations

Simple Interest Calculator
python
p = float(input("Enter Principal: "))
t = float(input("Enter Time (years): "))
r = float(input("Enter Rate: "))

si = (p * t * r) / 100
print("Simple Interest is:", si)

Area and Perimeter of a Rectangle
python
length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))

area = length * breadth
perimeter = 2 * (length + breadth)

print("Area:", area)
print("Perimeter:", perimeter)

Temperature Converter (Celsius to Fahrenheit)
python
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)
Conditional Statements (if-else)
Odd or Even Number
python
num = int(input("Enter a number: "))

if num % 2 == 0:
    print("The number is Even.")
else:
    print("The number is Odd.")
Pass or Fail Checker
python
marks = float(input("Enter your marks: "))

if marks >= 35:
    print("Result: Pass")
else:
    print("Result: Fail")
UGreatest of Three Numbers
python
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a >= b and a >= c:
    print("Greatest number is:", a)
elif b >= a and b >= c:
    print("Greatest number is:", b)
else:
    print("Greatest number is:", c)
Loops (for & while)
Sum of First 10 Natural Numbers
python
total_sum = 0

for i in range(1, 11):
    print(i)
    total_sum = total_sum + i

print("Total Sum is:", total_sum)
Multiplication Table
python
num = int(input("Enter a number for the table: "))

for i in range(1, 11):
    print(num, "x", i, "=", num * i)
Even Numbers Between 1 and 50
python
for i in range(1, 51):
    if i % 2 == 0:
        print(i, end=" ")

Comments