Suggested Python Practicals for Class XI

1️⃣ Input a welcome message and display it
msg = input("Enter a welcome message: ")
print("Welcome Message:", msg)
2️⃣ Input two numbers and display the larger and smaller number
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b:
print("Larger:", a)
print("Smaller:", b)
else:
print("Larger:", b)
print("Smaller:", a)
3️⃣ Input three numbers and display the largest and smallest number
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
largest = max(a, b, c)
smallest = min(a, b, c)
print("Largest:", largest)
print("Smallest:", smallest)
4️⃣ Pattern Programs (Using Nested Loops)
Pattern–1
*
**
***
****
*****
for i in range(1, 6):
for j in range(i):
print("*", end="")
print()
Pattern–2
12345
1234
123
12
1
for i in range(5, 0, -1):
for j in range(1, i+1):
print(j, end="")
print()
Pattern–3
A
AB
ABC
ABCD
ABCDE
for i in range(1, 6):
for j in range(i):
print(chr(65 + j), end="")
print()
5️⃣ Sum of Series
(a) 1 + x + x² + x³ + ... + xⁿ
x = int(input("Enter x: "))
n = int(input("Enter n: "))
s = 0
for i in range(n+1):
s = s + x**i
print("Sum =", s)
(b) 1 − x + x² − x³ + ... ± xⁿ
x = int(input("Enter x: "))
n = int(input("Enter n: "))
s = 0
for i in range(n+1):
if i % 2 == 0:
s += x**i
else:
s -= x**i
print("Sum =", s)
(c) x + x²/2 + x³/3 + ... + xⁿ/n
x = int(input("Enter x: "))
n = int(input("Enter n: "))
s = 0
for i in range(1, n+1):
s = s + (x**i)/i
print("Sum =", s)
(d) x + x²/2! + x³/3! + ... + xⁿ/n!
x = int(input("Enter x: "))
n = int(input("Enter n: "))
fact = 1
s = 0
for i in range(1, n+1):
fact = fact * i
s = s + (x**i)/fact
print("Sum =", s)
6️⃣ Check Perfect / Armstrong / Palindrome Number
Hint
Perfect Number: A positive integer that is equal to the sum of its proper positive divisors (excluding the number itself). The first few perfect numbers are 6, 28, 496, and 8128.
- Example: The proper divisors of 6 are 1, 2, and 3. Their sum is
1+2+3=6.
Armstrong Number: Also known as a narcissistic number, it is a number that is equal to the sum of its own digits, each raised to the power of the total number of digits in the number.
- Example: 153 is a 3-digit Armstrong number because
13+53+33=1+125+27=153.
- Example: 1634 is a 4-digit Armstrong number because
14+64+34+44=1+1296+81+256=1634.
Palindrome Number: A number (or a string) that reads the same backward as forward.
Example: 78987 is a palindrome number because it reads the same in either direction.
Example: 121 is a palindrome number because its reverse is also 121.
n = int(input("Enter number: "))
# Palindrome
if str(n) == str(n)[::-1]:
print("Palindrome Number")
# Armstrong
temp = n
s = 0
digits = len(str(n))
while temp > 0:
d = temp % 10
s += d ** digits
temp //= 10
if s == n:
print("Armstrong Number")
# Perfect
sum_div = 0
for i in range(1, n):
if n % i == 0:
sum_div += i
if sum_div == n:
print("Perfect Number")
7️⃣ Prime or Composite Number
n = int(input("Enter number: "))
count = 0
for i in range(1, n+1):
if n % i == 0:
count += 1
if count == 2:
print("Prime Number")
else:
print("Composite Number")
8️⃣ Fibonacci Series
n = int(input("Enter number of terms: "))
a, b = 0, 1
print(a, b, end=" ")
for i in range(n-2):
c = a + b
print(c, end=" ")
a, b = b, c
9️⃣ GCD and LCM of Two Numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
x, y = a, b
while y != 0:
x, y = y, x % y
gcd = x
lcm = (a * b) // gcd
print("GCD =", gcd)
print("LCM =", lcm)
🔟 Count vowels, consonants, uppercase, lowercase
s = input("Enter string: ")
vowels = consonants = upper = lower = 0
for ch in s:
if ch.isupper():
upper += 1
if ch.islower():
lower += 1
if ch.lower() in "aeiou":
vowels += 1
elif ch.isalpha():
consonants += 1
print("Vowels:", vowels)
print("Consonants:", consonants)
print("Uppercase:", upper)
print("Lowercase:", lower)
1️⃣1️⃣ Palindrome String & Change Case
s = input("Enter string: ")
if s == s[::-1]:
print("Palindrome String")
else:
print("Not a Palindrome")
print("Uppercase:", s.upper())
print("Lowercase:", s.lower())
1️⃣2️⃣ Largest and Smallest in List/Tuple
lst = [10, 5, 25, 3, 18]
print("Largest:", max(lst))
print("Smallest:", min(lst))
1️⃣3️⃣ Swap Even and Odd Index Elements
lst = [1, 2, 3, 4, 5, 6]
for i in range(0, len(lst)-1, 2):
lst[i], lst[i+1] = lst[i+1], lst[i]
print("After Swapping:", lst)
1️⃣4️⃣ Search an Element in List/Tuple
lst = [10, 20, 30, 40]
x = int(input("Enter element to search: "))
if x in lst:
print("Element Found")
else:
print("Element Not Found")
1️⃣5️⃣ Dictionary: Students with Marks Above 75
students = {}
n = int(input("Enter number of students: "))
for i in range(n):
roll = int(input("Enter roll number: "))
name = input("Enter name: ")
marks = int(input("Enter marks: "))
students[roll] = [name, marks]
print("Students scoring above 75:")
for roll in students:
if students[roll][1] > 75:
print(students[roll][0])
Just tell me 👍