Write a simple function
In the last video, Hugo described the basics of how to define a function. You will now write your own function!
Define a function, shout(), which simply prints out a string with three exclamation marks '!!!' at the end. The code for the square() function that we wrote earlier is found below. You can use it as a pattern to define shout().
def square():
new_value = 4 ** 2
return new_value
Note that the function body is indented 4 spaces already for you. Function bodies need to be indented by a consistent number of spaces and the choice of 4 is common.
This course touches on a lot of concepts you may have forgotten, so if you ever need a quick refresher, download the Python for Data Science Cheat Sheet and keep it handy!
Questo esercizio fa parte del corso
Introduction to Functions in Python
Istruzioni dell'esercizio
- Complete the function header by adding the appropriate function name,
shout. - In the function body, concatenate the string,
'congratulations'with another string,'!!!'. Assign the result toshout_word. - Print the value of
shout_word. - Call the
shoutfunction.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Define the function shout
def ____():
"""Print a string with three exclamation marks"""
# Concatenate the strings: shout_word
# Print shout_word
print(____)
# Call shout