Dark Mode

Class 11 Computer Science - Python Questions

Welcome to the Python practice questions and solutions for Class 11 Computer Science.

PYTHON PRACTICE QUESTIONS

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 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.3) 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.4) Generate the following pattern using the nested loops:

 *
 **
 ***
 ****
 *****

for i in range (6):
    for j in range (i):
        print("*", end="")
    print()

Q.5) 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.5) 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.6) 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.7) 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.8) 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.9) 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.10) 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.11) 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.12) 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.13) 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.14) Write a python program to take imput and display prime or not prime.

x=int(input("Enter the number:"))
for i in range(2,x):
    if x%2==0:
        print("It is not a prime number")
        break
else:
    print("It is a prime number")

Q.15) 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.16) 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.17)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.18) 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.19) 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.20) 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.21) 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.22) 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)