05.04 Comparing Procedural And Oop - Quiz¶
Check your understanding
-
What is the main difference between procedural and object-oriented programming?
- Procedural is faster than OOP
- Procedural uses functions while OOP uses classes
- Procedural organizes code as functions operating on data, while OOP bundles data and methods together { data-correct }
- OOP is always better than procedural
-
Which programming approach would be best for a simple temperature conversion program?
- Object-oriented programming
- Procedural programming { data-correct }
- Both are equally good
- Neither approach works
-
Look at this code. What approach does it represent?
def calculate_area(length, width): return length * width def calculate_perimeter(length, width): return 2 * (length + width)- Object-oriented programming
- Procedural programming { data-correct }
- Functional programming
- Event-driven programming
-
When would object-oriented programming be the better choice?
- For simple mathematical calculations
- For modeling real-world entities with complex state { data-correct }
- For processing a single list of data
- For basic input/output operations
-
What is a key advantage of procedural programming?
- Better code reuse through inheritance
- Encapsulation of data
- Simplicity and directness for straightforward problems { data-correct }
- Polymorphism support
-
In object-oriented programming, what replaces global variables for storing data?
- Function parameters
- Object attributes { data-correct }
- Return values
- Local variables
-
Which scenario would benefit most from object-oriented programming?
- Calculating the average of numbers in a list
- A video game with players, enemies, and items { data-correct }
- Converting text to uppercase
- Finding the maximum value in an array
-
What is the first step when converting procedural code to object-oriented?
- Create inheritance hierarchies
- Add polymorphism
- Identify data that belongs together { data-correct }
- Write more functions
-
Which statement about trade-offs between paradigms is correct?
- OOP is always more efficient than procedural
- Procedural programming is always easier to maintain
- OOP provides better modularity for complex systems { data-correct }
- There are no trade-offs between paradigms
-
Look at this code structure. What principle does it demonstrate?
class Student: def __init__(self, name): self.name = name self.grades = [] def add_grade(self, grade): self.grades.append(grade)- Functions operating on separate data
- Data and methods bundled together { data-correct }
- Global variable usage
- Procedural decomposition