ComenzarEmpieza gratis

Identifying modular code in Python

You've learned about the separation of responsibilities and several reasons why writing modular code matters. You've also seen one example of what modular code can look like in Python. Can you recognize the example from the possible answers below that is making use of modular code?

A:

def get_higher_value(x, y):
    if x >= y:
         higher_value = x
    else:
         higher_value = y
    return higher_value

higher_value1 = get_higher_value(1, 2)
higher_value2 = get_higher_value(3, 4)

B:

x1 = 1
y1 = 2

if x1 >= y1:
    higher_value = x1
else:
    higher_value = y1

x2 = 1
y2 = 2

if x2 >= y2:
    higher_value = x2
else:
    higher_value = y2

Este ejercicio forma parte del curso

Programming Paradigm Concepts

Ver curso

Ejercicio interactivo práctico

Pon en práctica la teoría con uno de nuestros ejercicios interactivos

Empezar ejercicio