Python Basic Programs
1. Write a program to print Hello World.
print("Hello World")
2. Write a program to add two numbers.
a = 5
b = 3
sum = a + b
print("Sum =", sum)
3. Write a program to subtract two numbers.
a = 10
b = 4
sub = a - b
print("Subtraction =", sub)
4. Write a program to multiply two numbers.
a = 6
b = 7
mul = a * b
print("Multiplication =", mul)
5. Write a program to divide two numbers.
a = 20
b = 4
print("Division =", a / b)
6. Write a program to find the remainder of two numbers.
a = 17
b = 5
print("Remainder =", a % b)
7. Write a program to find the square of a number.
a = 4
print("Square =", a * a)
8. Write a program to find the cube of a number.
a = 3
print("Cube =", a * a * a)
9. Write a program to calculate Simple Interest.
p = 1000
r = 5
t = 2
si = (p * r * t) / 100
print("Simple Interest =", si)
10. Write a program to find the average of two numbers.
a = 8
b = 6
average = (a + b) / 2
print("Average =", average)
11. Write a program to check whether two numbers are equal.
a = 5
b = 5
if a == b:
print("Both numbers are equal")
12. Write a program to check whether one number is greater than another.
a = 9
b = 4
if a > b:
print("a is greater than b")
13. Write a program to check whether one number is less than another.
a = 3
b = 7
if a < b:
print("a is less than b")
14. Write a program to check whether a number is greater than or equal to another.
a = 6
b = 6
if a >= b:
print("a is greater than or equal to b")
15. Write a program to check whether a number is less than or equal to another.
a = 5
b = 8
if a <= b:
print("a is less than or equal to b")
16. Write a program to check whether two numbers are not equal.
a = 4
b = 6
if a != b:
print("Numbers are not equal")
17. Write a program to compare two numbers using relational operators.
a = 10
b = 5
print(a, ">", b, "=", a > b)
print(a, "<", b, "=", a < b)
print(a, "==", b, "=", a == b)
18. Write a program to check whether a number is positive.
a = 7
if a > 0:
print("Number is positive")
19. Write a program to check whether a number is negative.
a = -5
if a < 0:
print("Number is negative")
20. Write a program to check whether a number is zero.
a = 0
if a == 0:
print("Number is zero")