The default value


#1

def repeat_stuff(stuff, num_repeats=10): isn’t 10 here adefault value why the output came like
return stuff*num_repeats this?

lyrics = repeat_stuff("Row ", 3) + “Your Boat”
song = repeat_stuff(lyrics)

print(song)

output:
Row Row Row Your BoatRow Row Row Your BoatRow Row Row Your BoatRow Row Row Your BoatRow Row Row Your BoatRow Row Row Your BoatRow Row Row Your BoatRow Row Row Your BoatRow Row Row Your BoatRow Row Row Your Boat

shouldn’t be only Row Row Row Your Boat


#2

if you print lyrics, the output would indeed Row Row Row your boat

however, you then repeat the lyrics 10 times to make a song.


#3

but i 've only multiplied stuff with num_repeated and i didn’t multiply lyrics with 10


#4

uhm… yes, you did:

song = repeat_stuff(lyrics)

and given you didn’t provide a second argument, the default value (10) will be used. So you did multiply lyrics with 10


#5

Thank you , I haven’t notice that


#6

so you understand now? I noticed you didn’t notice


#7

I understand now thank you


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.