Skip to content

This textbook is in beta – content is actively being refined. Report issues or suggestions

05.04 Comparing Procedural And Oop - Quiz

Check your understanding

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. In object-oriented programming, what replaces global variables for storing data?

    • Function parameters
    • Object attributes { data-correct }
    • Return values
    • Local variables
  7. 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
  8. 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
  9. 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
  10. 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