Questions about the specifics of strings

It’s always worth taking things step by step to hunt down an issue. In this case we can work backwards.
Since this is not throwing an error we can assume that print is using the contents of lyrics. The variable lyrics is a concatenation of the result of calling str() with repeat_stuff and "Your Boat. "
What is repeat_stuff in your code?

As an aside what are you doing with the values returned from calling repeat stuff?

Got stuck in the same mate, I had to capitalize Boat, was all the morning thinking in this… :dizzy_face:

1 Like

I can’t complete section 6, I don’t know why but I get this error message : Value for song did not match the expected value.

Here is my code :

def repeat_stuff(stuff, num_repeats=10):

return stuff * num_repeats

repeat_stuff("Row ",3)

lyrics = str(repeat_stuff) + "Your Boat. "

song = repeat_stuff(lyrics)

What are you doing with the values returned from your function? Are they assigned to anything?
repeat_stuff references a function object. What is the output when you print this object?

I had this issue and it turned out to be the capitalization on the different words. The green light likes to be extremely specific on these exercises.

Hi, I am getting an error in section 4 repeat_stuff() missing 1 required positional argument: ‘num_repeats’ for my code (below) but I can’t figure out why

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

repeat_stuff("Row ",10)

Your code seems valid so I can only assume one of the background tests is causing that error to appear.

Section 4 asks for the default value of the num_repeats parameter to be set to 10. This would allow the function to be called with just one argument (which is what I assume the background testing is doing) but since your code hasn’t added the default value an error is thrown intead.

A quick recap on default parameters-

def func(x=3):  # parameter x defaults to 3
    return x


func()  # the default allows this to be called without arguments.
func(3)  # the default is ignored when an argument is passed to it.
1 Like

Your suggestion worked, thank you!

Ignore this please. Thanks.

Hi,

One line one you need to remove = 10

On line four you need to add a comma and then the number 10 at the end) - song = repeat_stuff(lyrics, 10)

This should work.

Do not ignore this, it is always good to learn more. This webpage provides good information about default arguments.

@bit1814593747, since the num_repeats parameter is assigned a default value of 10, it isn’t necessary to input an argument for this parameter when calling the repeat_stuff function.

You can input two arguments when calling the function, with the argument you input being the one used in the function’s execution, but if you are fine with the default value assigned to num_repeats being used, it isn’t necessary to input a second argument. In this case, repeat_stuff with execute with the argument values "Row " and 10.

@cakerino, you are initializing lyrics to a string that shows the location of the function repeat_stuff and concatenating it to `“Your Boat.”

You do not need to remove = 10 on line 1 (this is simply assigning a default value for a parameter) or add a comma and 10 on line 4.

When you write str(repeat_stuff), its value is not equal to repeat_stuff("Row ", 3). Calling the function on the fourth line returns stuff * num_repeats, but this is not saved to any variable. Using str(repeat_stuff) instead returns the location of the function in your computer’s memory.

Try using str(repeat_stuff("Row ", 3)) instead of str(repeat_stuff).

here is what worked for me:

def repeat_stuff(stuff, num_repeats=10):

return stuff*num_repeats

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

song = repeat_stuff(lyrics)

print(song)

hi, can some one please explain for this particular exercise, How exactly we got the output we did?
I mean, what made Row"" to print 3 times, and over all out put to print 10 times?
I can see for default we had " num_repeats"= 10, and then we did stuff* num_repeats, that resulted in 10 prints, but how and where exactly we got 3 “Rows” from in the out put??

new to coding!!!

this is the output I got:

Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat.

It depends what steps you took to get there. Did you perhaps use the repeat_stuff function on the string 'Row'?

==============================================

def repeat_stuff (stuff, num_repeats):

return stuff*num_repeats

repeat_stuff("Row ",3)

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

song = repeat_stuff (lyrics, 1)

print (song)

My logic

So, I finally did this and got the result and I am not sure if what I did was right or wrong. Please help.
As per the exercise, I had initially made num_repeats = 10, but when calling it finally, I changed it to 1.

So, stuff = Row, num_repeats = 3
Calling the function with the arguments Row, 3 i.e., repeat_stuff("Row ",3) gave me Row Row Row
Then, I went ahead and concatenated "Row Row Row " with “Your Boat” and stored it in lyrics
So, basically, lyrics = Row Row Row Your Boat

Then song = repeat_stuff (stuff, num_repeats) = repeat_stuff (lyrics, 1)
So Row Row Row Your Boat was printed 1 time.

Please let me know if I am wrong. I am super new to this and really appreciate your help.

this is for the project- getting ready for physics class

7 assignment

my input-

print(“The GE train supplies " + str(train_force) + " Newtons of force.”)

OUT put

File “script.py”, line 18
print(“The GE train supplies " + str(train_force) + " Newtons of force.”)
^
SyntaxError: invalid character in identifier

Question -

can some one please explain why I am getting this error? it seems right to me, and similar thing was done on the video by the instructor for this project

Hello @suran6jana and welcome to the Codecademy Forums!

Please format your code using the </> button. It looks like you call repeat_stuff() on line 3 and again on line 4. However, only the call on line 4 is used. repeat_stuff("Row ", 3) on line 3 is redundant and should be removed from your code. Otherwise, it looks good!

In case anyone else has this as well, my issue with this was that I put a space between repeat_stuff and the parenthesis: repeat_stuff ("Row ", 3). This prevented my code from clearing Step 2. When I deleted that space, it worked. But apparently having no space is not a requirement of python, because if I put the space back in it still clear step 3.

1 Like