Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to avoid repeating the same logic in multiple places.
LLD
def calculate_area(radius): return [1] * radius * radius
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the number 3.14 directly instead of a constant.
✗ Incorrect
Using a constant like pi avoids repeating the value everywhere.
2fill in blank
mediumComplete the code to reuse the function instead of repeating the calculation.
LLD
def get_discounted_price(price, discount): return price - (price * discount) final_price = [1](100, 0.1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that does not exist or misspelling the function name.
✗ Incorrect
Calling get_discounted_price reuses the logic and avoids repetition.
3fill in blank
hardFix the error in the code to avoid repeating the same query logic.
LLD
def fetch_users(): query = "SELECT * FROM users WHERE active = 1" return [1](query) def fetch_admins(): query = "SELECT * FROM users WHERE active = 1 AND role = 'admin'" return execute_query(query)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that is not defined or inconsistent.
✗ Incorrect
Using the same function execute_query avoids repeating query execution logic.
4fill in blank
hardFill both blanks to create a reusable function and call it correctly.
LLD
def [1](data): processed = [x * 2 for x in data] return processed result = [2]([1, 2, 3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for function definition and call.
✗ Incorrect
Defining and calling the function process_data avoids repeating processing logic.
5fill in blank
hardFill all three blanks to create a reusable class method and use it properly.
LLD
class Calculator: def [1](self, a, b): return a + b calc = Calculator() result = calc.[2](5, 7) print([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for method and call, or printing wrong variable.
✗ Incorrect
Defining the method add, calling it, and printing the result avoids repeating addition logic.