HELP - Strange printed message returned by code


#1
  1. Review functions

The code keeps returning at the end print:

<function shut_down at 0x7fbba2ee7b18>

Not entirely sure how this is coming about.

```python

Below is my code

def shut_down(s):
(4)if (s) == “yes”:
(8)return “Shutting down”
(4)elif (s) == “no”:
(8)return “Shutdown aborted”
(4)else:
(8)return “Sorry”

In brackets I’ve indicated the number of spaces I’ve used for the whitespace for the respective line.

<do not remove the three backticks above>

#2

Do you mean that (the quote above) is printing to the console? You’re calling your function incorrectly (in a way that only prints the information about it). Do you know how to call functions?


#3

Cheers for the reply,

I’m not entirely sure what you mean:

The task is as follows:

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”

From my understanding I’ve called the function to return a string depending on s, makes sense to print it afterwards so I can get visual feedback as to what value of s was input.

I’ve defined the function to output the strings depending on s, my main query is where that console output is coming from.


#4

The return keyword ends the function, returning whatever is associated with it, like return "Sorry" for instance… that will return "Sorry" if the else statement is executed.

But here:

When we call a function, we use the function name and insert any argument/s within parentheses so the function knows what to use/do when it’s called.

I don’t see where you have called your function in your code… If you can copy and paste it here in Preformatted text, that’d be great.

more info : https://www.tutorialspoint.com/python/python_functions.htm


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.