FAQ: Introduction to Functions - Review


#1

This community-built FAQ covers the “Review” exercise from the lesson “Introduction to Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Hi there, quick question!

I understand that with the ‘lyrics’ variable we over-road the number 10 in the function and therefore “Row” appeared 3 times. I’m just wondering what part of the code told “print” to display the whole function 10 times?


#3

This
lyrics = repeat_stuff("Row ", 3) + "Your Boat. "
runs the function giving two arguments, therefore overwriting the 10.

The second step
song = repeat_stuff(lyrics)
runs the function again but this time you’re not overwriting the default num_repeats argument of 10 since you’re not giving a second argument.


#4

I think that when we put (“row”, 3) it defines num_repeats as 3, but when we put just (lyrics) with out any specified number, it used the defined default of 10 applied in step four. I think.


#5

Hi guys,

I’m currently stuck at sub exercise 2. which states

Outside of the function, call repeat_stuff .

You can use the value "Row " for stuff and 3 for num_repeats .

what does that translate into python ?

I can’t seem to get it to greenlight it to move to step 3.


#7

Make sure you put the space behind “Row” so that it is "Row ".


#8

Make sure your code is not indented two spaces for this line:

repeat_stuff("Row ", 3)


#9

Hey, thanks for the help!


#10

Why is it that when you define the variable lyrics without the 10 being default it won’t run even though in lyrics we defined both positional arguments?


#11

num_repeats will be 10 if we do not supply a second positional argument.

lyrics = repeat_stuff("Row ") + "Your Boat\n"
Row Row Row Row Row Row Row Row Row Row Your Boat

If we supply no arguments it will raise an exception.

TypeError: repeat_stuff() missing 1 required positional argument: 'stuff'

If we supply a number in the first position, it will also raise an exception:

TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’

Note that we are building lyrics before passing it to create song.

Row Row Row your boat

is the lyrics,

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

is the song, as in,

song = repeat_stuff(lyrics)