0
0
Pythonprogramming~20 mins

Procedural vs object-oriented approach in Python - Practice Questions

Choose your learning style9 modes available
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
intermediate
2: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)
ATypeError
B8
C53
D15
Attempts:
2 left
💡 Hint
Multiply length by width to get the area.
Predict Output
intermediate
2: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())
A15
BTypeError
C8
DNone
Attempts:
2 left
💡 Hint
The method area multiplies length and width stored in the object.
🧠 Conceptual
advanced
2:00remaining
Difference in data handling between procedural and OOP
Which statement best describes how data is handled differently in procedural vs object-oriented programming?
AProcedural programming groups data and functions together; OOP separates them.
BProcedural programming uses objects to store data; OOP uses global variables.
COOP groups data and functions together inside objects; procedural programming keeps them separate.
DOOP does not use functions; procedural programming only uses functions.
Attempts:
2 left
💡 Hint
Think about where data and behavior live in each approach.
Predict Output
advanced
2: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)
ATypeError
B
1
1
C
0
1
D
1
0
Attempts:
2 left
💡 Hint
The function calls the object's method to increase count.
🧠 Conceptual
expert
2:00remaining
Advantages of object-oriented approach over procedural
Which of the following is the main advantage of using object-oriented programming over procedural programming?
AIt allows bundling data and behavior, making code easier to manage and reuse.
BIt requires fewer lines of code for all programs.
CIt always runs faster than procedural code.
DIt eliminates the need for functions.
Attempts:
2 left
💡 Hint
Think about how OOP helps organize code.