Great! So far you have learned:
- How to write a function
- How to give a function inputs
- How to return values from a function
- What scope means
Let’s practice these concepts again so that you won’t forget them!
Instructions
Define a function called repeat_stuff
that takes in two inputs, stuff
, and num_repeats
.
We will want to make this function print a string with stuff
repeated num_repeats
amount of times. For now, only put an empty print
statement inside the function.
Outside of the function, call repeat_stuff
.
You can use the value "Row "
for stuff
and 3
for num_repeats
.
Change the print
statement inside repeat_stuff
to a return
statement instead.
It should return stuff*num_repeats
.
Note: Multiplying a string just makes a new string with the old one repeated! For example:
"na"*6
results in the string "nananananana"
.
Give the parameter num_repeats
a default value of 10
.
Add repeat_stuff("Row ", 3)
and the string "Your Boat. "
together and save the result to a variable called lyrics
.
Create a variable called song
and assign it the value of repeat_stuff
called with the singular input lyrics
.
Print song
.
Good job!