0% found this document useful (0 votes)
4 views

Class11_Python_QP

This document is a Class 11 Python question paper with a total of 50 marks, divided into four sections covering basic concepts, loops, lists, dictionaries, functions, recursion, and file handling. Each section contains various programming problems, including checking for perfect numbers, generating prime numbers, and implementing a stack. There is also a bonus question for extra credit involving a simple calculator using recursion.

Uploaded by

Lavanya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Class11_Python_QP

This document is a Class 11 Python question paper with a total of 50 marks, divided into four sections covering basic concepts, loops, lists, dictionaries, functions, recursion, and file handling. Each section contains various programming problems, including checking for perfect numbers, generating prime numbers, and implementing a stack. There is also a bonus question for extra credit involving a simple calculator using recursion.

Uploaded by

Lavanya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Class 11 Python - Difficult Question Paper with Answers

Max Marks: 50 | Time: 2 Hours

---

Section A (Basic Concepts - 10 Marks)

1. Check if a number is Perfect (2 marks)


A perfect number is a number whose sum of divisors equals the number itself.

num = int(input("Enter a number: "))


sum_divisors = sum(i for i in range(1, num) if num % i == 0)
print("Perfect Number" if sum_divisors == num else "Not a Perfect Number")

2. Sum of digits using recursion (2 marks)

def sum_of_digits(n):
if n == 0:
return 0
return (n % 10) + sum_of_digits(n // 10)

num = int(input("Enter a number: "))


print("Sum of digits:", sum_of_digits(num))

3. Find the second largest number in a list (3 marks)

numbers = list(map(int, input("Enter numbers: ").split()))


first, second = float('-inf'), float('-inf')
for num in numbers:
if num > first:
second, first = first, num
elif num > second and num != first:
second = num
print("Second Largest:", second)
4. Check if a string is a palindrome using slicing (3 marks)

s = input("Enter a string: ")


print("Palindrome" if s == s[::-1] else "Not a palindrome")

---

Section B (Loops, Lists, and Dictionaries - 15 Marks)

5. Generate first 'n' prime numbers (3 marks)

def is_prime(n):
return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5) + 1))

n = int(input("Enter n: "))
primes = [num for num in range(2, 1000) if is_prime(num)][:n]
print("First", n, "prime numbers:", primes)

6. Frequency of characters in a string using dictionary (3 marks)

s = input("Enter a string: ")


char_freq = {char: s.count(char) for char in set(s)}
print("Character Frequency:", char_freq)

7. Find intersection of two lists (3 marks)

list1 = list(map(int, input("Enter first list: ").split()))


list2 = list(map(int, input("Enter second list: ").split()))
print("Common Elements:", list(set(list1) & set(list2)))

8. Nested dictionary for student records (3 marks)

students = {"Alice": {"Math": 85, "Science": 90}, "Bob": {"Math": 78, "Science": 88}}
for student, subjects in students.items():
print(student, "Total Marks:", sum(subjects.values()))

9. Sort list of tuples based on marks (3 marks)


students = [("Alice", 85), ("Bob", 90), ("Charlie", 78)]
students.sort(key=lambda x: x[1], reverse=True)
print("Sorted List:", students)

---

Section C (Functions and Recursion - 10 Marks)

10. Convert decimal to binary using recursion (5 marks)

def decimal_to_binary(n):
return "" if n == 0 else decimal_to_binary(n // 2) + str(n % 2)

num = int(input("Enter a number: "))


print("Binary:", decimal_to_binary(num) if num else "0")

11. Return unique elements from a list using recursion (5 marks)

def unique_list(lst, seen=set()):


if not lst:
return []
return ([lst[0]] if lst[0] not in seen else []) + unique_list(lst[1:], seen | {lst[0]})

numbers = list(map(int, input("Enter numbers: ").split()))


print("Unique Elements:", unique_list(numbers))

---

Section D (File Handling & Advanced Questions - 15 Marks)

12. Count lines, words, and characters in a file (3 marks)

with open("sample.txt", "r") as f:


data = f.read()
print("Lines:", len(data.split('\n')))
print("Words:", len(data.split()))
print("Characters:", len(data))
13. Replace words in a file (3 marks)

word_to_replace = input("Enter word to replace: ")


replacement = input("Enter replacement: ")
with open("sample.txt", "r") as f:
data = f.read().replace(word_to_replace, replacement)
with open("sample.txt", "w") as f:
f.write(data)

14. Store and retrieve student records in a file (3 marks)

students = {"Alice": 85, "Bob": 90}


with open("students.txt", "w") as f:
for name, marks in students.items():
f.write(f"{name}:{marks}\n")

15. Implement a stack using list (3 marks)

stack = []
def push(val): stack.append(val)
def pop(): return stack.pop() if stack else "Stack is empty"
def display(): print(stack)

16. Find the longest word in a string (3 marks)

sentence = input("Enter a sentence: ")


print("Longest word:", max(sentence.split(), key=len))

---

Bonus Question (5 Marks - Extra Credit)

17. Simple calculator using recursion

def calculator():
a, op, b = input("Enter expression (e.g. 5 + 3): ").split()
a, b = int(a), int(b)
print(eval(f"{a}{op}{b}"))
if input("Continue? (y/n): ") == 'y':
calculator()
calculator()

---

This question paper tests logical thinking, recursion, file handling, and data structures. Good luck!

You might also like