0% found this document useful (0 votes)
98 views4 pages

Class XI Python Practical ALL Questions Answers

This document contains a practical worksheet for Class XI Computer Science focusing on Python programming. It includes 26 questions with corresponding code solutions covering various topics such as solving quadratic equations, checking even or odd numbers, generating patterns, and validating passwords. Each question is designed to enhance students' understanding of Python programming concepts and problem-solving skills.

Uploaded by

ADITYA VANJARI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views4 pages

Class XI Python Practical ALL Questions Answers

This document contains a practical worksheet for Class XI Computer Science focusing on Python programming. It includes 26 questions with corresponding code solutions covering various topics such as solving quadratic equations, checking even or odd numbers, generating patterns, and validating passwords. Each question is designed to enhance students' understanding of Python programming concepts and problem-solving skills.

Uploaded by

ADITYA VANJARI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Class XI – Computer Science (Python)

Python Practical Worksheet – ALL Questions with


Answers

1. Solve quadratic equation


import math
a=int(input())
b=int(input())
c=int(input())
d=b*b-4*a*c
if d>=0:
print((-b+[Link](d))/(2*a))
print((-[Link](d))/(2*a))
else:
print("No real roots")

2. Check even or odd


n=int(input())
if n%2==0:
print("Even")
else:
print("Odd")

3. Print table of a number


n=int(input())
for i in range(1,11):
print(n,"x",i,"=",n*i)

4. Count number of digits


n=input()
print(len(n))

5. Sum of digits
n=input()
s=0
for i in n:
s+=int(i)
print(s)

6. Convert decimal to binary


n=int(input())
print(bin(n)[2:])

7. Check prime number


n=int(input())
for i in range(2,n):
if n%i==0:
print("Not Prime")
break
else:
print("Prime")

8. Divisible by 7 but not multiple of 5 (2000–3000)


res=[]
for i in range(2000,3001):
if i%7==0 and i%5!=0:
[Link](str(i))
print(",".join(res))

9. Factorial of a number
n=int(input())
f=1
for i in range(1,n+1):
f*=i
print(f)

10. Generate pattern list


n=int(input())
print([i*i for i in range(1,n+1)])

11. Create list and tuple


x=input().split(',')
print(list(x))
print(tuple(x))

12. Formula Q = sqrt(2*C*D/H)


import math
C=50
H=30
D=int(input())
print(int([Link]((2*C*D)/H)))

13. Convert sentence to uppercase


s=input()
print([Link]())

14. Remove duplicate words & sort


s=input().split()
print(" ".join(sorted(set(s))))

15. Binary numbers divisible by 5


nums=input().split(',')
for i in nums:
if int(i,2)%5==0:
print(i,end=",")

16. Even digit numbers (1000–3000)


for i in range(1000,3001):
if all(int(d)%2==0 for d in str(i)):
print(i,end=",")

17. Count letters and digits


s=input()
l=d=0
for i in s:
if [Link](): l+=1
elif [Link](): d+=1
print("Letters:",l,"Digits:",d)

18. Count upper & lower case letters


s=input()
u=l=0
for i in s:
if [Link](): u+=1
elif [Link](): l+=1
print("Upper:",u,"Lower:",l)

19. Square odd numbers (list comprehension)


nums=input().split(',')
print([int(i)**2 for i in nums if int(i)%2!=0])

20. Password validation


import re
p=input()
if (6<=len(p)<=12 and [Link]('[a-z]',p) and [Link]('[A-Z]',p)
and [Link]('[0-9]',p) and [Link]('[$#@]',p)):
print("Valid Password")
else:
print("Invalid Password")

21. Sort tuples (name, age, score)


data=[('Tom',19,80),('John',20,90),('Tom',18,85)]
print(sorted(data))

22. Square of a number (method)


def square(n):
return n*n
print(square(int(input())))

23. Fibonacci sequence


n=int(input())
a,b=0,1
for i in range(n):
print(a,end=",")
a,b=b,a+b

24. Binary search


def binary_search(lst,x):
low=0; high=len(lst)-1
while low<=high:
mid=(low+high)//2
if lst[mid]==x: return mid
elif lst[mid] else: high=mid-1
return -1

25. Reverse a string


s=input()
print(s[::-1])

26. Chickens and Rabbits problem


heads=85
legs=94
r=(legs-2*heads)//2
c=heads-r
print("Rabbits:",r,"Chickens:",c)

You might also like