Basic Python Programs for Class 11 - Informatics Practices
1. Sum of Two Numbers
Explanation: This program takes two numbers as input using the input() function, adds them, and
prints the result.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
sum = a + b
print("Sum is:", sum)
2. Check Even or Odd
Explanation: This checks if the number is divisible by 2. If true, it's even; otherwise, it's odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
3. Find Largest of Three Numbers
Explanation: Uses conditional statements to compare three numbers and print the largest one.
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("Largest number is:", a)
elif b >= c:
print("Largest number is:", b)
else:
print("Largest number is:", c)
4. Simple Calculator (Add, Subtract, Multiply, Divide)
Explanation: Performs basic arithmetic operations based on the user's choice.
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
op = input("Enter operator (+, -, *, /): ")
if op == '+':
print("Result:", a + b)
elif op == '-':
print("Result:", a - b)
elif op == '*':
print("Result:", a * b)
elif op == '/':
print("Result:", a / b)
else:
print("Invalid operator")
5. Check Leap Year
Explanation: Checks leap year using the standard leap year rules.
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
6. Print Multiplication Table
Explanation: Prints multiplication table for the entered number using a for loop.
num = int(input("Enter a number: "))
for i in range(1, 11):
print(num, "x", i, "=", num * i)
7. Factorial of a Number
Explanation: Calculates factorial by multiplying numbers from 1 to n.
n = int(input("Enter a number: "))
fact = 1
for i in range(1, n + 1):
fact *= i
print("Factorial is:", fact)
8. Reverse a Number
Explanation: Uses a while loop to reverse the digits of a number.
num = int(input("Enter a number: "))
rev = 0
while num != 0:
rev = rev * 10 + num % 10
num //= 10
print("Reversed number is:", rev)
9. Check Prime Number
Explanation: Checks if a number is divisible by any number from 2 to its square root. If yes, it's not
prime.
num = int(input("Enter a number: "))
is_prime = True
if num < 2:
is_prime = False
else:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print("Prime Number")
else:
print("Not a Prime Number")
10. Count Vowels in a String
Explanation: Loops through each character and checks if it is a vowel.
text = input("Enter a string: ")
count = 0
for char in text.lower():
if char in 'aeiou':
count += 1
print("Number of vowels:", count)
11. True Division (/)
Explanation: Performs true (float) division.
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
result = a / b
print("True division (a / b) is:", result)
12. Floor Division (//)
Explanation: Performs integer division (floor value).
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
result = a // b
print("Floor division (a // b) is:", result)
13. Remainder Division (%)
Explanation: Gives remainder after division.
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
result = a % b
print("Remainder (a % b) is:", result)
14. Addition, Subtraction, and Product
Explanation: Performs all three operations using input from user.
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
addition = a + b
subtraction = a - b
product = a * b
print("Addition:", addition)
print("Subtraction:", subtraction)
print("Product:", product)