Time: 30 minutes
Total Questions: 20
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.
Implement a decorator that measures and prints the execution time of a function.
Write a generator function fibonacci(n) that yields the first n Fibonacci numbers.
Create a custom exception class NegativeNumberError and modify a function that calculates square roots to raise this exception for negative inputs.
Implement a class that inherits from str and adds a method reverse() that returns the reversed string.
Write a function that uses **kwargs to accept keyword arguments and formats them into a string.
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.
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.
Implement a class hierarchy demonstrating multiple inheritance with a Shape base class and Circle and Square derived classes. Use super() properly.
Write a context manager for database connections that automatically commits on success and rolls back on exceptions.
Create a function that demonstrates duck typing by working with objects that have a calculate_area() method regardless of their actual type.
Write a recursive function to calculate the factorial of a number with memoization.
Implement a custom metaclass that creates classes with automatically generated string representations.
Write a function that uses *args and **kwargs to create a flexible function that can handle various input patterns.
Create a class that implements all comparison magic methods (__eq__, __lt__, __le__, etc.) for comparing objects based on an attribute.
Write a function that uses zip() to combine multiple iterables and processes them in parallel.
Implement a linked list class with Node and LinkedList classes, supporting append, prepend, and delete operations.
Write a function that uses eval() safely by restricting it to only evaluate mathematical expressions.
Create a class that extends list and implements a custom __contains__ method for O(1) membership testing using a set internally.
Write a function that demonstrates the use of globals() and locals() to access and modify variable scopes.
End of Test Set 3