Problem with: Learn Python / Introduction to Functions / 7. Keyword Arguments


#1

Hi guys,

I’m totally new to coding and a few days into the Python course.

I have got totally stuck on the above lesson, I would massively appreciate any help!

I have been a couple of hours on this now and I cannot for the life of me figure out what I have missed for part one, having to use the plus signs around the word title.

This is the first step:

Define a function called create_spreadsheet that takes one argument, title , and only prints the string "Creating a spreadsheet called [TITLE]" , where [TITLE] is replaced with the value of title .

This is the code that passes the step:

def create_spreadsheet(title):
print(“Creating a spreadsheet called “+title+””)

create_spreadsheet(“Downloads”)

This is the code that I have been trying to use from my limited/poor knowledge and description:

def create_spreadsheet(title):
print(“Creating a spreadsheet called [TITLE]”)

create_spreadsheet(“Downloads”)

Is the lesson missing some text that teaches us about the plus signs or am being REALLY stupid?

Thanks all,
Adam


#2

Please post the URL to this exercise. Thanks.


#3

https://www.codecademy.com/paths/computer-science/tracks/cspath-intro/modules/cspath-python-functions/lessons/intro-to-functions/exercises/multiple-parameters

Thanks buddy


#4

Codecademy has locked us out of the Pro courses. You’ll have to take your question to the Slack channel or ping an advisor.


#5

That should have been covered under concatenation.

Only strings can be concatenated to strings.

"Some text " + some_string

When concatenating numbers to a string, be sure to use the str() constructor to convert the number to a string.

That’s the short and narrow of concatenation.


#6

Really appreciate that mtf!

I think I’m going to have to go over old ground again, I seem to be forgetting a lot :frowning:


#7

Something to keep in mind when you get to Lists and Dictionaries…

dict objects (as well as set objects) cannot be concatenated, but list objects can be.

>>> {'one':1} + {'two': 2}
Traceback (most recent call last):
  File "<pyshell#128>", line 1, in <module>
    {'one':1} + {'two': 2}
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'
>>> [{'one':1}] + [{'two': 2}]
[{'one': 1}, {'two': 2}]
>>> 

This is not something we can expect in other languages, so Python must be using .extend() in the background.

>>> [1, 2, 3, 4, 5] + [6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

The repeat operator, * must also be using .extend() and the list() constructor in the background to make this work…

>>> row = ['O'] * 10
>>> row
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O']
>>> 

Note that the operator can be used on string objects.

>>> ays = 'a' * 10
>>> ays
'aaaaaaaaaa'
>>> x = 42
>>> y = str(x) * 5
>>> x = int(y)
>>> y
'4242424242'
>>> x
4242424242
>>> 

#11