Class11_Python_QP
Class11_Python_QP
---
def sum_of_digits(n):
if n == 0:
return 0
return (n % 10) + sum_of_digits(n // 10)
---
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)
students = {"Alice": {"Math": 85, "Science": 90}, "Bob": {"Math": 78, "Science": 88}}
for student, subjects in students.items():
print(student, "Total Marks:", sum(subjects.values()))
---
def decimal_to_binary(n):
return "" if n == 0 else decimal_to_binary(n // 2) + str(n % 2)
---
stack = []
def push(val): stack.append(val)
def pop(): return stack.pop() if stack else "Stack is empty"
def display(): print(stack)
---
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!