Below is some code that has been deliberately broken so that you can fix it.
The code is supposed to generate 10 random nice things to say about a computer (I know, that’s incredibly geeky, sorry):
- Fix the syntax error
Hint: Look at the function definition. You should have
def, the name of the function, brackets (containing any parameters if there are any) then a colon
- Fix the logic error so the function returns a value
Hint: A subprogram that doesn’t return a value is a procedure not a function. This code chooses a random
complimentbut it doesn’t return that value
- Fix the logic error so 10 compliments are displayed
Hint: This code only displays 8 compliments. Change it so that the loop executes 10 times instead.
On the next page you’ll get some ideas for projects where you can use functions in your own projects