Welcome to the Python practice questions and solutions for Class 11 Computer Science. This page consists of 40+ python questions for class 11 students
Q.1) Input a welcome message and display it.
x=input("Enter a welcome message")
print(x)
Q.2) Input two numbers and display the Sum, Substract, Divition and multiplication.
x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
s=x+y
m=x*y
d=x/y
c=x-y
print("The addition of these number is",s)
print("The multiplication of these number is",m)
print("The divition of these number is",d)
print("The substraction of these number is",c)
Q.3) Input two numbers and display the larger/smaller number.
x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
if x>y:
print(f"The larger number is {x} and smaller number is {y}")
elif x < y:
print(f"The larger number is {y} and smaller number is {x}")
else:
print("Both the numbers are same")
Q.4) Input Three numbers and display the larger/smaller number.
x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
z=int(input("Enter the third number:"))
if x>y and x>z:
print(f"The larger number is {x}")
elif y>x and y>z:
print(f"The largest number is {y}")
elif z>x and z>y:
print(f"The largest number is {z}")
else:
print("All the numbers are same")
Q.5) Write a program to find simple interest.
x=int(input("Enter the priciple ammount:"))
r=int(input("Enter the rate of interest:"))
t=int(input("Enter the time:"))
s=(p*r*t)/100
print("Simple interest is",s)
Q.6) Write a program to find square and print it.
x=int(input("Enter the first number:"))
s=x**2
print("The square of",x,"is",s)
Q.7) Write a program to convert celcius to fehrenhiet.
x=int(input("Enter the first number:"))
f=((9/5)+x)+32
print("The temperature in fehrenhiet is",f)
Q.8) Write a program to print the area of a circle
x=float(input("Enter the radius of circle:"))
a=3.14*(x**2)
print("The area of circle is",a)
Q.9) Write a program to print the area and perimeter of a rectangle.
x=float(input("Enter the length of rectangle:"))
y=float(input("Enter the breadth of rectangle:"))
a=x*y
p=2*(x+y)
print("Area of rectangle is",a,"and the perimeter of the rectangle is",p)
Q.10) Write a program to swap two numbers.
x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
print("Before swapping the value of x is",x,"and y is",y)
x=x+y
y=x-y
x=x-y
print("After swapping the value of x is",x,"and y is",y)
Q11) Write a program to check a user is elligible to vote or not.
x=int(input("Enter your age:"))
if x>=18:
print("You are eligible to vote")
else:
print("You are not eligible")
Q.12) Write a program to take marks of indiviual subject and print the final percentage and grade
e=float(input("Enter your marks in English:"))
s=float(input("Enter your marks in Science:"))
m=float(input("Enter your marks in Maths:"))
h=float(input("Enter your marks in Hindi:"))
c=float(input("Enter your marks in Social science:"))
p=(e+s+m+h+c)/5
print("Your final percentage is",p,"%")
if p>90:
print("A+")
elif p>80 and p<=90:
print("A")
elif p>70 and p<=80:
print("B")
elif p>60 and p<=70:
print("C")
elif p>50 and p<=60
print("D")
else:
print("Fail")
Q.13) Write a program to input a year from user and print that it is a leap year or not.
x=int(input("Enter the year:"))
if (x%4==0 and x%100!=0) or (x%400==0):
print(x,"is a leap year")
else:
print(x,"is not a leap year")
Q.14) Write a program to input three number and print the greatest number.
a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
c=int(input("Enter the third number:"))
if a>b and a>c:
print("The greatest number is", a)
elif b>a and b>c:
print("The greatest number is", b)
elif c>a and c>b:
print("The greatest number is", c)
else:
print("All are equal")
Q.15) Write a program to input three numbers and print in ascending order.
x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
z=int(input("Enter the third number:"))
if x < y < z:
print("The ascending order is", x,y,z)
elif x < z < y:
print("The ascending order is", x,z,y)
elif y < x < z:
print("The ascending order is", y,x,z)
elif y < z < x:
print("The ascending order is", y,z,x)
elif z < x < y:
print("The ascending order is", z,x,y)
elif z < y < x:
print("The ascending order is", z,y,x)
else:
print("All the numbers are same")
Q.16) Generate the following pattern using the nested loops:
* ** *** **** *****
for i in range (6):
for j in range (i):
print("*", end="")
print()
Q.17) Generate the following pattern using the nested loops:
1 12 123 1234 12345
for i in range (1,6):
for j in range (1,i+1):
print(j, end="")
print()
Q.18) Generate the following pattern using the nested loops:
12345 1234 123 12 1
for i in range (5,0,-1):
for j in range (i):
print(j, end="")
print()
Q.19) Generate the following pattern using the nested loops:
54321 5432 543 54 5
for i in range (1,6):
for j in range (5,i-1,-1):
print(j, end="")
print()
Q.20) Generate the following pattern using the nested loops:
A AB ABC ABCD ABCDE
for i in range(6):
for j in range (65,65+i):
print(chr(j), end="")
print()
Q.21) Write a program to input the value of x and n and print the sum of the following series: 1+X+X2+X3+X4.......Xn
x=int(input("Enter the number:"))
y=int(input("Enter the power:"))
c=0
for i in range(0,n+1):
c+=x**i
print(c)
Q.22) Write a program to input the value of x and n and print the sum of the following series: 1-X+X2-X3+X4.......Xn
x=int(input("Enter the number:"))
y=int(input("Enter the power:"))
c=0
for i in range (0,y+1):
c+=((-1)**i)*(x**i)
print(c)
Q.23) Write a program to create a dictionary with names of employees, their salary and access them.
dc={}
x=int(input("How many employees do you want to add:"))
for i in range (x):
nm=input("Enter the emplyee name:")
sl=int(input("Enter the salary of emplyee:"))
dc[nm]=sl
print(dc)
Q.24) Write a program to input a number between 1 to 7 and print the corresponding day of the week. eg:- 1=Sunday 2=Monday 3=Tuesday
x=int(input("Enter the number:"))
if x==1:
print("Sunday")
elif x==2:
print("Monday")
elif x==3:
print("Tuesday")
elif x==4:
print("Wednesday")
elif x==5:
print("Thursday")
elif x==6:
print("Friday")
elif x==7:
print("Saturday")
else:
print("Enter a valid number")
Q.25) Write a python script to scheck whether a given key already exists in a dictionary.
dc={1:10,2:20,3:30}
x=int(input("Enter the key:"))
if x in dc:
print("Key is valid")
else:
print("Key is not valid")
Q.26) Write a python program to print string in the following pattern:
S CC HHH OOOO OOOOO LLLLLL
x="SCHOOL"
l=len(x)
for i in range(0,6):
for j in range(0,i+1):
print(x[ i ], end="")
print()
Q.27) Write a python program that takes an integer as input and return positive if the number is greater than 0, and negative if the number is less than 0, and zero if it is 0.
x=int(input("Enter the integer number:"))
if x>0:
print("Positive")
elif x<0:
print("Negative")
else:
print("Zero")
Q.28) Write a python program to take input a list of numbers and find the largest and smallest number in it.
numbers=list(map(int,input("Enter numbes separated by space:").split()))
largest=max(numbers)
smallest=min(numbers)
print(f"Largest number is {largest}")
print(f"Smallest number is {smallest}")
Q.29) Write a python program to take input and display prime or not prime.
x=int(input("Enter the number:"))
for i in range(2,x):
if x%i==0:
print("It is not a prime number")
break
else:
print("It is a prime number")
Q.30) Write a program to print all prime numbers between a given range by user input.
s=int(input("Enter the start number:"))
e=int(input("Enter the end number:"))
for i in range (s, e+1):
c=0
n=i
for j in range (1, n+1):
if (n%j==0):
c+=1
if c==2:
print(n,"is a prime number")
Q.31) Write a program to take input and display odd or even.
x=int(input("Enter a number:"))
if x%2==0:
print("It is a even number")
else:
print("It is a odd number")
Q.32) Write a program to take input of start and end index from user and find the sum of odd and even numbers between that given range.
x=int(input("Enter the start number:"))
y=int(input("Enter the end number:"))
s1=0
s2=0
for i in range (x,y+1):
if i%2==0:
s1+=i
else:
s2+=i
print("Sum of even numbers is", s1)
print("Sum of odd numbers is", s2)
Q.33) Write a program to input from user using while loop 5 times and print the sum
sum=0
i=0
while (i<5):
a=int(input("Enter any number:"))
sum=sum+a
i+=1
print("Sum is",sum)
Q.34) Write a program to input a list and find the element from it.
l=list(input("Enter the list:").split())
n=input("Enter the element to search:")
for i in l:
if n in str(i):
print(n,"is present in the list")
break
else:
print(n,"is not present in the list")
Q.35)Write a program to remove duplicates from dictionary.
dc = {1: 10, 2: 20, 3: 30, 2: 20, 5: 50, 6:20}
new_dc = {}
seen_values = []
for key, value in dc.items():
if value not in seen_values:
new_dc[key] = value
seen_values.append(value)
else:
print(value, "is a duplicate")
print(new_dc)
Q.36) Write a program to print the following series. a+ar+ar2+ar3+......+arn
a=int(input("Enter the first number:"))
r=int(input("Enter the second number:"))
n=int(input("Enter the power:"))
if r==1:
s=a*n
else:
s=a*(1-r**n)/(1-r)
print(s)
Q.37) Write a program to find the number of times an element occurs in the list.
l=[22,45,34,22,48,99,22,50] print(l.count(22))
Q.38) Write a python program to input a string and count the number of vowels in the string.
x=input("Enter a string:")
c=0
for i in x:
if x in "AEOIUaeiou":
c=c+1
print("Number of vowels in this sting is",c)
Q.39) Find factorial using for and while loop.
Using for loop:-
x=int(input("Enter any number:"))
fact=1
for i in range (1,x+1):
fact=fact*i
print(f"The factorial of this number is {fact}")
Using while loop:-
a=int(input("Enter the number:"))
fact=1
x=1
while x<a+1:
fact=fact*x
x=x+1
print(fact)
Q.40) Write a program to find maximum, minimum and mean value of the given list. [10,20,30,40,50]
x=[10,20,30,40,50]
x.sort()
print("Maximum number is",x[-1])
print("Minimum number is",x[0])
sum=0
c=0
for i in x:
sum=sum+i
c=c+1
print("Mean number is", sum/c)