17. Review: Functions


#1

This is my code

  1. def shut_down(s):
  2. return message
    3.
  3. if shut_down():
  4. speak("Shutting down")
  5. elif no():
  6. speak("Shutdown aborted")
  7. else:
  8. speak("Sorry")

This is my error
Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: shut_down() takes exactly 1 argument (0 given)

HELP!


#2

Hi @0610001009,

I would recommend that you follow the instructions given - they are very detailed, and very useful.

First, def a function, shut_down, that takes one argument s. Don't forget the parentheses or the colon!
Then, if the shut_down function receives an s equal to "yes", it should return "Shutting down"
Alternatively, elif s is equal to "no", then the function should return "Shutdown aborted".
Finally, if shut_down gets anything other than those inputs, the function should return "Sorry".

Let me know if you don't understand the instructions! :slight_smile:


#3

I don't understand, that's why I am asking for help.


#4

Okay @0610001009,

Just wanted to make sure you've familiarised yourself with the instructions already :stuck_out_tongue:

Let us go through the instructions step by step:

1. First, def a function, shut_down, that takes one argument s. Don't forget the parentheses or the colon!

You did this step already, and it is correct. So step one, check.

2. Then, if the shut_down function receives an s equal to "yes", it should return "Shutting down"

In the function which you defined, it takes a parameter s. Right now, the instructions say that if this s equals to "yes", it should return "Shutting down". This means that you have to set an if statement, and something like this:

if s == "yes":
    return "Shutting down"

instead of whatever you were trying to achieve by doing:

This same logic can be applied to steps 3 and 4:

3. Alternatively, elif s is equal to "no", then the function should return "Shutdown aborted".

4. Finally, if shut_down gets anything other than those inputs, the function should return "Sorry"

Why not give it another try?

P.S. You were probably following the example code extremely tightly, but I think it is just there to jolt your memory as to how to define functions and the corresponding syntax...not for direct copy and pasting. Take some time to think about what you are doing with each line of code...


#5

2 posts were split to a new topic: I can't find the problem here


#7

2 posts were split to a new topic: IndentationError: expected an indented block"


#8

A post was merged into an existing topic: IndentationError: expected an indented block"


#9

If i remove the return s line it turns me with this error:

" File "python", line 2
if s == "yes":
^
IndentationError: expected an indented block"


#10

look at the error. it says that it is an indentation error, so consider shifting the if and elif and else statements within your function! :slight_smile:


#11

A post was split to a new topic: Is there something wrong?


#12

i struggled a bit with this, the argument asked for is a string data type, you are asking it to compare it in your if section. however you are not presenting your comparison yes and no as a string. the difference between this working and not working is the quotation marks that designate the yes and no as "yes" string, and yes - not string.
also you are taking the example as a cut and paste operation. try building it from what you have learned step by step and not by copying the example, that will get you no where.


#13

Where's the speak function? You are calling the speak function but it's not there.


#15