Challenge - 5 Problems
Master of Procedural and Object-Oriented Programming
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of procedural code for area calculation
What is the output of this procedural Python code that calculates the area of a rectangle?
Python
def area(length, width): return length * width result = area(5, 3) print(result)
Attempts:
2 left
💡 Hint
Multiply length by width to get the area.
✗ Incorrect
The function multiplies 5 by 3, resulting in 15.
❓ Predict Output
intermediate2:00remaining
Output of object-oriented code for area calculation
What is the output of this object-oriented Python code that calculates the area of a rectangle?
Python
class Rectangle: def __init__(self, length, width): self.length = length self.width = width def area(self): return self.length * self.width rect = Rectangle(5, 3) print(rect.area())
Attempts:
2 left
💡 Hint
The method area multiplies length and width stored in the object.
✗ Incorrect
The Rectangle object stores 5 and 3, and area() returns 15.
🧠 Conceptual
advanced2:00remaining
Difference in data handling between procedural and OOP
Which statement best describes how data is handled differently in procedural vs object-oriented programming?
Attempts:
2 left
💡 Hint
Think about where data and behavior live in each approach.
✗ Incorrect
OOP bundles data and related functions inside objects, while procedural programming keeps data and functions separate.
❓ Predict Output
advanced2:00remaining
Output of mixed procedural and OOP code
What is the output of this code mixing procedural and object-oriented styles?
Python
class Counter: def __init__(self): self.count = 0 def increment(self): self.count += 1 def increment_counter(counter): counter.increment() return counter.count c = Counter() print(increment_counter(c)) print(c.count)
Attempts:
2 left
💡 Hint
The function calls the object's method to increase count.
✗ Incorrect
increment_counter calls increment(), increasing count to 1, then returns 1. The object's count is also 1.
🧠 Conceptual
expert2:00remaining
Advantages of object-oriented approach over procedural
Which of the following is the main advantage of using object-oriented programming over procedural programming?
Attempts:
2 left
💡 Hint
Think about how OOP helps organize code.
✗ Incorrect
OOP bundles data and related functions inside objects, improving code organization and reuse.