0
0
LLDsystem_design~10 mins

DRY (Don't Repeat Yourself) in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Api
B3.14
Cradius
Darea
Attempts:
3 left
💡 Hint
Common Mistakes
Using the number 3.14 directly instead of a constant.
2fill in blank
medium

Complete 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'
Acalculate_price
Bprice_after_discount
Cget_discounted_price
Ddiscount_price
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that does not exist or misspelling the function name.
3fill in blank
hard

Fix 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'
Aquery_execute
Brun_query
Cfetch_data
Dexecute_query
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that is not defined or inconsistent.
4fill in blank
hard

Fill 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'
Aprocess_data
Bprocess
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for function definition and call.
5fill in blank
hard

Fill 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'
Aadd
Cresult
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for method and call, or printing wrong variable.