Top Ad unit 728 × 90

Libreoffice

Libreoffice Writer

Python Basic Programs


    Python Basic Programs



    Add two numbers in Python

a = input("First number: ")

b = input("Second number: ")

res = float(a) + float(b)

print(res)


Find Maximum of two numbers in Python



a = 7
b = 3
print(max(a, b))

or

a = 7
b = 3

if a > b:
    print(a)
else:
    print(b)


Output


7



Factorial of a Number - Python



n = 6

 fact = 1

for i in range(1, n + 1):
    fact *= i
print(fact)


Output

720



Python Program for Simple Interest



principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the interest rate (%): "))
time = float(input("Enter the time (years): "))

simple_interest = (principal * rate * time) / 100

print("Simple Interest:",simple_interest)



Python Program to Check Armstrong Number




num = int(input("Enter a number: "))
n = num
power = len(str(num))
total = 0

while n > 0:
    digit = n % 10
    total += digit ** power
    n //= 10

if total == num:
    print("Armstrong Number")
else:
    print("Not an Armstrong Number")


Output

153 is an Armstrong number


Python Program for Compound Interest




P = 1200   
R = 5    
T = 2      

A = P * (1 + R/100) ** T
CI = A - P

print("Compound interest:", CI)


Output


123



Python Program to Find Area of a Circle



PI = 3.142
r = 5 # radius
area = PI * (r * r)
print(area)


Output

78.55


Python Program to Find Area of a Rectangle




length= float(input("Enter the length of the rectangle: "))
width= float(input("Enter the width of the rectangle: "))

area = (length*width)
print("The area of the rectangle is:", area)



Python Program to Find Area of a Square



side= float(input("Enter the Side of the Square: "))
area=(side*side)
print("The area of the Square is:", area)



Python Program to Find Area of a Triangle



base= float(input("Enter the base of the triangle: "))
height= float(input("Enter the height of the triangle: "))

area = (base*height)/2
print("The area of the triangle is:" area)


Python Program to Find Area of a  trapezium



height = float(input("Height of trapezoid: "))
base1 = float(input('Base one value: '))
base2 = float(input('Base two value: '))
area = ((base1 + base2) / 2) * height
print("The Area of Trapezium:", area)


Python Program to Find Area of a Parallelogram


base = float(input('Length of base: '))
height = float(input('Measurement of height: '))
area = base * height
print("Area is: ", area)



Python Program to Find Area of a Sphere



pi=22/7
radius= float(input('Radius of sphere: '))
surface area = 4 * pi * radian **2
volume = (4/3) * (pi * radian ** 3)
print("Surface Area is: ", surface area)
print("Volume is: ", volume)
Python Basic Programs Reviewed by ADcomputercampus on November 23, 2025 Rating: 5

No comments:

Contact Form

Name

Email *

Message *

Powered by Blogger.