Python Tutorial Help


#1

def repeat_stuff(stuff,num_repeats=10):
return stuff*num_repeats
lyrics= (repeat_stuff("Row ", 3) + "Your Boat. ")
song=repeat_stuff(lyrics)
print(song)

Why is the output this:
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.

Instead of this:
Row Row Row Your Boat. Row Row Row Your Boat. Row Row Row Your Boat.

I thought the default didn’t get used unless there was only one input in the function repeat_stuff.
Please explain!


#2

absolutely true, but here:

song=repeat_stuff(lyrics)

there is only one argument (or input as you name it) to function call, so the default (10) gets used

this program uses the repeat_stuff function twice: once to make the lyrics and once to make the song.


#3

Wow, I see that now. :smile: Thanks for the speedy response!


#4

Fine and good in this instance. One should not rely upon such support, going forward. Ask a lot a questions of the same responder and you may as well be them. Spread your own wings.


#5

I see your point but I disagree. I prefer to ask too many questions than to ask too little. It seems to make the learning process go by faster. However, if learning code is dissimilar to learning stuff in school, id be more than willing to change.