FAQ: Introduction to Functions - Review

The above screen shows only too clearly what your mistake is. There is a missing : (colon). May I suggest resetting the lesson and follow through the steps (if for only entertainment) with this syntax error corrected.

This explanation has been the most helpful to my misunderstanding. However, what I would like to know now is how we are overwriting the default argument num_repeats of 10 in line 1. I would have assumed that if the argument num_repeats was made default to 10 that I would get an error when assigning the argument num_repeats an int of 3 later on. I hope this makes sense. Thank you.

The default parameter is only used if no argument is passed to the function in its place, e.g.

def example(x=3):
    return x
print(example())  # Without an argument, output is: 3
print(example(5))  # Out: 5
print(example())  # Falling back to the default again. Out: 3

Ok yes, Thank you that makes sense to me now. I appreciate your time.

1 Like

At step 3 and not sure what I am doing wrong


def repeat_stuff(stuff, num_repeats):
  return stuff*num_repeats

repeat_stuff("Row ", 3)
1 Like

Could you provide details of the error? Is there a specific message outputted to say what the problem is?

It’s also worth having a little look at the following post on how to format code since indentation is so important in Python-


Outside of the function, call repeat_stuff .
You can use the value "Row " for stuff and 3 for num_repeats .

ans =

repeat_stuff("Row ",3)

Why is it necessary to put a space after Row and before closing quotation mark ?

repeat_stuff(“some_string”,n) returns “some_string” concantenated n times withous any spaces between. So you’ll get “RowRowRow” in case of repeat_stuff(“Row”,3) instead of "Row Row Row ".

1 Like

print(“The GE train supplies” + str(train_force) +
“Newtons of force”)
SyntaxError: invalid syntax

What is the problem here ?

Difficult to say without seeing the full code. Please also use format:

How do I format code in my posts?

so the indent(ion) of your code shows on the forum

I’ve tried to make this as legible as possible, thanks for your patience.

I’m stuck on 5 of 7 on the review of row row row your boat, below is an exact copy of the solution, when i take that piece, and paste it into my work it still doesnt fulfill the requirements of 5. im confused, im not sure if im braindead but this review is a lot to digest.

lyrics = repeat_stuff("Row ", 3) + "Your Boat. "

why doesnt the above fulfill the requirements for 5?

additionally, the below confuses me from the solution, im trying to digest it but maybe someone could provide some words of wisdom. we first define repeat_stuff, and make it return stuff*num_repeats, then we set ‘num_repeats = 10’ why is it printing row row row your boat 10x in the solution and not ‘row row row’ (10x) then ‘your boat’?

lyrics = repeat_stuff("Row ", 3) + "Your Boat. "

song = repeat_stuff(lyrics)

Default values for parameters (num_repeats = 10) means when no argument is provided, the default value is used

when you do provide an argument for the parameter, that value is used, not the default/fallback.

1 Like

thanks, ive reset my progress once to go over what ive missed… evidently i missed that a second time.

Hello Guys,
Hope you all are well.

I have a question related to this exersice. How can I get those 10 lines output in new line. For example Iam getting this output now.
’ Row Row Row Your Boat. Row Row Row Your Boat.’
‘Row Row Row Your Boat. Row Row Row Your Boat.’

how to get each Row Row Row Row Boat line in different line.
For example:- How to get this kind of output

  1. Row Row Row Your Boat.
  2. Row Row Row Your Boat.
  3. Row Row Row Your Boat.
  4. Row Row Row Your Boat.

Here is my code and this is giving me a error

def repeat_stuff(stuff,num_repeats=10):
  return stuff*num_repeats

lyrics=repeat_stuff("Row ",3)+"Your Boat. "+ /n

using new line doesn’t like a bad idea? Except that new line is with a backslash (\n) and should be part of the string.

Thanks so much @stetim94 for the reply.
Oh that backslash n (\n) was my mistake.

So does this means “new line” can’t be used here and can only be used when we are printing or doing other stuff with a string?

New line is just a special string character and \n gets converted to that character inside a string literal or similar (e.g. wrapped with " " qutation marks). You could concatenate it to another string with something like "a string" + "\n" but it must be part of a string for that character to be used.

Quick question,

why do we use
song = repeat_stuff(lyrics)
to run the code?
When do we use your_function(your_input)?

Because that is the applicable function call and argument. The return value is assigned to song.

We are using the pattern, with actual names for function and argument.

1 Like

same here
its step 2 and im getting this error:

Expected "Row " with a single space after "Row" to be passed into the function repeat_stuff .