FAQ: Introduction to Functions - Types of Arguments

If you copy/paste your code (using the Preformatted text button </>) here, it may offer some clues as to why your code is not working.
In jamesjasonw’s code, the issue is that in the print statement, the concatenation operator is missing.
Instead of print(... + ", and lastly" final destination),
it should be
print(... + ", and lastly " + final destination)

Perhaps your code isn’t matching the expected output exactly.

In step 6, you are asked to use only 2 positional arguments to see how the default argument is used for the final_destination parameter. (What to put in the ? when I call the function in the code below)

I wanted to try and also see if I could provide positional arguments for the 1st and 3rd parameter and let the 2nd parameter be the default argument. But I am not sure how to leave the 2nd argument blank?

def trip_planner(first_destination=“Iceland”, second_destination=“India”, final_destination=“Germany”):
print(“Here is what your trip will look like!”)
print("First, we will stop in " + first_destination + “, then”, second_destination + ", and lastly " + final_destination)

trip_planner(“Brooklyn”, ? ,“Queens”)

I got everything to work, although my output looked like:

“First, we will stop in France , then Germany , and lastly Denmark”

with spaces between the arguments and the commas. How would i get rid of those spaces? Here is how i had the function written:

def trip_planner(first_destination, second_destination, final_destination = “Codecademy HQ”):
print(“Here is what your trip will look like!”)
print(“First, we will stop in”, first_destination, “, then”, second_destination, “, and lastly”, final_destination)

1 Like

Fix the spacing in the strings you’re printing and concatenating.

but how would i include commas in the argument portions of that concatenation? I’m using commas to separate the strings and arguments already. How would you write it?

Look at the person’s code above :arrow_up: from 3 months ago to see how to concatenate strings and syntactical elements. Or, research “string concatenation” in Python.

“Some string, “ + “ “ + “some other string, “
#or however you want it formatted. 

Got it. thank you! appreciate it

1 Like

@nickickss Welcome to the forums!

This is a bit late but might help others with the same issue, when you use concatenate with the +, the strings are ‘glued’ together as is.

If you think about what you are typing, if your strings are “First, we will stop in” and “France”, concatenating them will not add the extra space even though it’s not natural for us to have them in the quotations. Python doesn’t know what characters are in your strings that makes the sentence flow when you concatenate them, so you have to do it yourself.

Hi @css8483852472, welcome to the forums!

See the response from @tgrtim above:

You can’t have a parameter with a default argument in between positional parameters with no default. All default arguments need to be at the end of the function definition parameter list.

@chip7846616466 just to add to this. It is possible to do it with the comma method in the print statement, but keep in mind that by default for the print function, all arguments separated by comma are concatenated with a space attached.

The print function has a default argument “sep” that indicates the default separator between arguments. You can redefine this as sep=“”.

So your code can look like:

def trip_planner(first_destination, second_destination, final_destination = "Codecademy HQ"): print("Here is what your trip will look like!") print("First, we will stop in ", first_destination, ", then ", second_destination, ", and lastly ", final_destination, sep="") trip_planner("France", "Germany", "Denmark")

got it that makes sense. thank you for the tip!

1 Like

in case you’re still struggling with question3 here’s the code:

def trip_planner(first_destination, second_destination, final_destination=“Codecademy HQ”):
print(“Here is what your trip will look like!”)
print(f"First, we will stop in {first_destination}, then {second_destination}, and lastly {final_destination}")

trip_planner(‘France’, ‘Germany’, ‘Denmark’)

What in the world is going on here? I think it is right but it is not showing that it is. advice?

Since the instructions are asking for positional arguments as opposed to keyword arguments, try doing:

trip_planner('Brooklyn', 'Queens')
2 Likes

That worked out! I thought my code was good since I was getting the correct answer. Thanks for the advice. I will look more closely at what they are asking for.

For anyone who stumbled on step 6, even though the instructions appear to show keyword arguments, they’re looking for positional arguments. Meaning, don’t type out first_destination = “Brooklyn”, second_destination = “Queens”

Instead, call the functions with just “Brooklyn” and “Queens” as parameters and let your function definition provide the default value for final_destination

Hope this helps

1 Like

def trip_planner(first_destination, second_destination):
print(“Here is what your trip will look like!”)
print("First, we will stop in " + first_destination + " then " + second_destination + " and lastly ")

trip_planner(‘Brooklyn’,‘Queens’)

#If you understand questions but the code doesn’t work, delete all the codes and copy paste above the code then pass question 6.

1 Like

I don’t understand what I am doing wrong, and wondering if there is a bug?