Do we need to define the variables seperately?

Why can’t this example be done by just formatting the arguments within the function, then specifying all of the arguments when calling it, instead of going through the hassle of creating whole new variables within the code?

def poem_description(publishing_date, author, title, original_work):
  poem_desc = "The poem {title} by {author} was originally published in {original_work} in {publishing_date}.".format(publishing_date = publishing_date, author = author, title = title, original_work = original_work)
  return poem_desc

my_beard_description = poem_description("1974", "Shel Silverstein", "My Beard", "Where the Sidewalk Ends")

print(my_beard_description)

This seems to work on my end, but the “solution” went through, what seem to me to be unnecessary steps.

Hi @hipstergw,

Your code certainly works just as well as the longer solution that defines new variables prior to calling the function. Perhaps the author of the exercise wished to offer a pattern that could easily be modified outside the confines of the exercise to ask the user for input, as follows, prior to calling the function:

print("Please enter the following information.")
author = input("Name of author: ")
title = input("Title of poem: ")
original_work = input("Original work: ")
publishing_date = input("Publishing date: ")
my_beard_description = poem_description(publishing_date, author, title, original_work)
print(my_beard_description)
9 Likes

Yeap, never thought there was a different solution to this exercise but yours. But i also agree with appylpye that it offers more flexibility and readability, because in that case you could just change the variables at the beginning and not go to the function and hardcode the arguments.

i don’t understand what is beard_discription just please tell me i don’t know i am still a beginner

what is beard_description just tell me i am in the first step of this Exercise

Hello, @method1989593843, and welcome to the Codecademy Forums!

The reason for beard_discription and other variables is so that information about the poem could be saved for later use, in case you or another programmer wishes to expand the program at a later time. In that case, the saved information could be used in another portion of the program.

Does this not rely on you entering the arguments in the correct order?
This solution lets you add the arguments in any order; the code can still put them into the correct place?

def poem_description(publishing_date, author, title, original_work):

poem_desc = “The poem {title} by {author} was originally published in {original_work} in {publishing_date}.”.format(publishing_date=publishing_date, author=author, title=title, original_work=original_work)

return poem_desc

my_beard_description = poem_description(author = “Shel Silverstein”, title = “My Beard”, original_work = “Where the Sidewalk Ends”, publishing_date = “1974”)

print(my_beard_description)

#return is : The poem My Beard by Shel Silverstein was originally published in Where the Sidewalk Ends in 1974.

1 Like

This is exactly how I entered my solution. I believe the important note is that your arguments can be entered in any order, as long as you include the “=” with them.

def poem_description(publishing_date, author, title, original_work):
  poem_desc = "The poem {title} by {author} was originally published in {original_work} in {publishing_date}.".format(publishing_date=publishing_date, author=author, title=title, original_work=original_work)
  return poem_desc

my_beard_description = poem_description(publishing_date="1974", title="My Beard", original_work="Where the Sidewalk Ends", author="Shel Silverstein")
print(my_beard_description)