Question in python
The following two programs produce the same output. Which of the following is the benefit
of writing code the second way?
Example :
favorite inputWhats your favorite type of drink?"
printI say water and you say", favorite
if favorite "water":
printWe said the same thing!"
healthy inputWhat do you think is the healthiest type of drink?"
printI say water and you say", healthy
if healthy "water":
printWe said the same thing!"
Example :
def saydrink:
printI say water and you say", drink
if drink "water":
printWe said the same thing!"
favorite inputWhats your favorite type of drink?"
say favorite
healthy inputWhat do you think is the healthiest type of drink?"
sayhealthy
The second way creates a function and all programs require a function to be created
The second way allows for user input, which cannot be done using the first way
The second way allows code to be reused rather than rewritten