Python Development Course
Chapter
>
Level
Creating your own Functions
Function arguments
Objective
Use a custom function to water all the crops on the field writing no more than thirteen (13) lines of code.
An argument is the value you enter in the parenthesis of certain functions, when creating custom functions you are able to assign arguments to add some variation to the code the fiction executes.
There are several crops that need watering in succession, use a custom function to simplify your code and reduce the amount of lines you need to write.
def water_crops(count):
for x in range(count):
player.move_forward(2)
player.turn_left()
player.water()
player.turn_right()
The variable count in the above code is an argument, with this function, not only are you able to run a loop using this single line of code but you are also able to set how many times you would like the loop to repeat. For example: writing water_crops(4) will run the for loop inside the function four (4) times.
Define and use this function to water the crops writing no more than thirteen (13) lines of code.