11th Standard CBSE Practical’s
1. Input a welcome message and display it.
message= input("Enter your welcome message: ")
print(message)
2. Input two numbers and display the larger/ smaller number.
#larger number code
num1=int(input("Enter first number:"))
num2=int(input("Enter second number:"))
if num1>num2:
print(num1,"is greater")
else:
print(num2,"is greater")
#smaller number code
num1=int(input("Enter first number:"))
num2=int(input("Enter second number:"))
if num1<num2:
print(num1,"is smaller")
else:
print(num2,"is smaller")
3. Input three numbers and display the largest/ smallest number.
num1=int(input("Enter First Number"))
num2=int(input("Enter Second Number"))
num3=int(input("Enter Third Number"))
#Check if first number is greater than rest of the two numbers.
if (num1> num2 and num1> num3):
print("The Largest number is", num1)
#Check if Second number is greater than rest of the two numbers.
elif (num2 > num1 and num2> num3):
print ("The Largest number is", num2)
else:
print ("The Largest number is", num3)
4. Genrate the following patterns using nested loop
for i in range(1,6):
for j in range(i,6):
print(i,end="")
print()
5. write a program to input the value of x and n and print the sum of the following series.
x = float(input("Enter base number :"))
n = int(input("Enter the power :"))
sum = 0
for a in range(1,n+1):
sum = sum + x ** a
print("sum of the series is ", sum)
6. Determine whether a number is a perfect number an armstrong number or a
palindrome.
print("program to check whether a number is a \n 1.perfect number,")
print("2.an armstrong or a")
print("3. palindrome.\n")
n = int(input("Enter any number"))
#for perfect number
sum1 = 0
for i in range(1,n):
if(n%i == 0):
sum1 = sum1 + i
if (sum1 == n):
print("1: The number",n,"is a perfect number!")
else:
print("1: The number",n,"is not a perfect number!")
#for Armstrong number
#calculated the length(number of digits)
order = len(str(n))
#intialize sum
sum= 0
#find the sum of the cube of each digit
temp = n
while temp>0:
digit = temp%10
sum +=digit**order
temp//=10
#display the result
if n == sum:
print("2:The number",n," is an armstrong number")
else:
print("2:The number",n," is not an armstrong number")
#for palindrome number
k=n
temp=n
rev=0
while(k>0):
dig=k%10
rev=rev*10+dig
k=k//10
if(temp==rev):
print("3:The number",n," is a palindrome!")
else:
print("3:The number",n," isn't a palindrome!")
7. Input a number and check if the number is a prime or not number.
num=int(input("Enter a number "))
fact=0
for a in range(2, num):
if num%a==0:
fact+=1
break
if fact==0:
print(num, "is prime")
else:
print(num, "is not prime")
8. display the nth fibonnaci number.
def fib(n):
if n <=1:
return 1
return fib(n-1) + fib(n-2)
pos= int (input("enter the position of fibonacci number: "))
print(fib(pos))
9. Count and display the number of vowels, consonants, uppercase, lowercase
characters in string.
s=input("Enter any string:")
v=c=u=l=0
for i in s:
if i.isalpha():
if i.lower() in 'aeiou':
v+=1
else:
c+=1
if i.isupper():
u+=1
if i.islower():
l+=1
print("vowels:",v)
print("consonants:",c)
print("uppercase:",u)
print("lowercase:",l)
10. Input a string and determine whether it is a palinrome or not convert the case of
characters in a string.
print("Input a string and determine whether it is a palindrome or not;\n")
print("convert the case of characters in a string.\n")
string=input(("Enter a string:"))
if (string==string[::-1]):
print("The string is a palindrome")
else:
print("Not a palindrome")
print("String after converting the case:",string.swapcase())
11. find the largest/smallest number in a list.
lst=[]
num=int(input('How many numbers:'))
for n in range(num):
numbers = int(input('Enter number'))
lst.append(numbers)
print("maximum element in the list is:",max(lst))
print("minimum element in the list is:",min(lst))
12. Input a list of numbers and swap elements at the even location with the elements at
the odd location.
lst=[]
num=int(input('How many numbers:'))
for n in range(num):
numbers=int(input('Enternumber'))
lst.append(numbers)
print("List before swaping:",lst)
for i in range(0,num,2):
temp1=lst[i]
temp2=lst[i+1]
lst[i]=temp2
lst[i+1]=temp1
print("List after swaping:",lst)
13. Input a list/tuple of elements, search for a given element in the list/tuple.
print("Program to input a list/tuple of elements, search for a given element in the list/tuple")
list=[]
num=int(input("How many numbers in the list:"))
for n in range(num):
numbers=int(input("Enter number"))
list.append(numbers)
print("the entered list is",list)
length = len(list)
element=int(input("Enter the element to be searched for:"))
for i in range(0,length):
if element==list[i]:
print(element,"found at index",i,"and position:",i+1)
break
else:
print(element," is not found!!!")
14. Input a list/tuple of numbers and find the smallest and largest number from the list.
mylist=[20,100,20,1,10]
mylist.sort()
print(mylist)
print("smallest element is :",mylist[0])
print("largest element is :",mylist[-1])
15. Create a dictionary with the roll number, name and marks of n students in a class
and display the names of students who have scored marks above 75.
print("create a dictionary with the roll number, name and marks of n students in a class and \n")
print("display the names of students who have scored marks above 75")
result={}
n= int(input("enter number of students:"))
for i in range(n):
print("enter details of students no.",i+1)
rno=int(input("roll no:"))
name=input("name:")
marks=int(input("marks:"))
result[rno]=[name,marks]
print(result)
for student in result:
if result[student][1]>75:
print(result[student][0])
OUTPUT SECTION
1. Input a welcome message and display it.
Input: Hello, Students!
Output: Hello, Students!
2. Input two numbers and display the larger/smaller number.
Input: 10, 20
Output: 20 is greater; 10 is smaller.
3. Input three numbers and display the largest/smallest number.
Input: 5, 15, 10
Output: The largest number is 15.
4. Generate the following pattern:
Output:
11111
2222
333
44
5
5. Sum of series (x^1 + x^2 + ... + x^n).
Input: x=2, n=3
Output: 2 + 4 + 8 = 14
6. Determine number type.
Input: 28
Output: 28 is a perfect number.
Input: 153
Output: 153 is an Armstrong number.
Input: 121
Output: 121 is a palindrome.
7. Check for a prime number.
Input: 17
Output: 17 is prime.
8. Display the nth Fibonacci number.
Input: 5
Output: 5th Fibonacci number is 5.
9. Count vowels, consonants, uppercase, lowercase in a string.
Input: "Hello World"
Output: Vowels: 3, Consonants: 7, Uppercase: 2, Lowercase: 8.
10. Check for palindrome & case conversion.
Input: "Madam"
Output: The string is a palindrome. Converted: "mADAM".
11. Find the largest/smallest number in a list.
Input: [12, 45, 2, 89, 33]
Output: Max: 89, Min: 2.
12. Swap elements at even-odd positions in a list.
Input: [1, 2, 3, 4, 5, 6]
Output: [2, 1, 4, 3, 6, 5]
13. Search for an element in a list/tuple.
Input: [10, 20, 30], Search: 20
Output: Found at index 1.
14. Find smallest/largest number in a list.
Input: [5, 8, 1, 3]
Output: Smallest: 1, Largest: 8.
15. Filter students with marks above 75.
Input: {1: ['Alice', 80], 2: ['Bob', 70], 3: ['Charlie', 90]}
Output: Alice, Charlie.