Skip to content

Latest commit

 

History

History
70 lines (46 loc) · 2.77 KB

File metadata and controls

70 lines (46 loc) · 2.77 KB

Python Test Set 3 - Hard

Time: 30 minutes
Total Questions: 20


Question 1

Write a custom class Stack that implements stack operations (push, pop, peek, is_empty) using a list. Include proper error handling for pop on empty stack.

Question 2

Implement a decorator that measures and prints the execution time of a function.

Question 3

Write a generator function fibonacci(n) that yields the first n Fibonacci numbers.

Question 4

Create a custom exception class NegativeNumberError and modify a function that calculates square roots to raise this exception for negative inputs.

Question 5

Implement a class that inherits from str and adds a method reverse() that returns the reversed string.

Question 6

Write a function that uses **kwargs to accept keyword arguments and formats them into a string.

Question 7

Create a custom container class that implements __getitem__, __setitem__, and __len__ to work like a list but stores data in a more memory-efficient way.

Question 8

Write a function that uses map() and filter() to process a list of dictionaries, filtering only items where price > 100 and applying a 10% discount.

Question 9

Implement a class hierarchy demonstrating multiple inheritance with a Shape base class and Circle and Square derived classes. Use super() properly.

Question 10

Write a context manager for database connections that automatically commits on success and rolls back on exceptions.

Question 11

Create a function that demonstrates duck typing by working with objects that have a calculate_area() method regardless of their actual type.

Question 12

Write a recursive function to calculate the factorial of a number with memoization.

Question 13

Implement a custom metaclass that creates classes with automatically generated string representations.

Question 14

Write a function that uses *args and **kwargs to create a flexible function that can handle various input patterns.

Question 15

Create a class that implements all comparison magic methods (__eq__, __lt__, __le__, etc.) for comparing objects based on an attribute.

Question 16

Write a function that uses zip() to combine multiple iterables and processes them in parallel.

Question 17

Implement a linked list class with Node and LinkedList classes, supporting append, prepend, and delete operations.

Question 18

Write a function that uses eval() safely by restricting it to only evaluate mathematical expressions.

Question 19

Create a class that extends list and implements a custom __contains__ method for O(1) membership testing using a set internally.

Question 20

Write a function that demonstrates the use of globals() and locals() to access and modify variable scopes.


End of Test Set 3