Review: Functions


#1



https://www.codecademy.com/en/courses/python-beginner-c7VZg/4/1?curriculum_id=4f89dab3d788890003000096

Traceback (most recent call last):
File "python", line 9, in
File "", line 1, in
NameError: name 'yes' is not defined

So, I just want to put an input question before the code, but I can't see wtf is going wrong.
I need some help here, and sorry for my bad English.


Replace this line with your code. 
def shut_down(s):
    if s == "yes":
        return "Shutting down"
    elif s == "no":
        return "Shutdown aborted"
    else:
        return "Sorry"
    
s = input("Do you want to shut_down the program? yes or no?")
print shut_down(s)


Review function<anyone spotting my wrong doing?
#2

input is a python3 function, not a python2 function. for python2 it is raw_input. But you don't need to use that in this exercise. Just give s a string value


#3

Then, if I replace the "input" for "raw_input" it's going to work?
I know that I don't need to use, but I like to test the codes.
Anyway, thank you!


#4

that was referring to raw_input. It will give you an error message that you don't need raw_input in this exercise, if you would have tried before posting a reply


#5

I thought you could actually use input in py 2? But it is used differently, in that it reads whatever is passed as code instead of actual user input?


#6

That is true, you can. But there was something different about it, but i forgot what.

The whole point is, that (raw_)input shouldn't be used in this exercise


#7

Out of all the lessons I've learned so far, def functions() seems to impede me insofar. What is the purpose of the return? And why is it different than just using print, assuming a value has been defined at the end of the program

for example, what's the difference between this:


def biggest_number(*args):
print max(args)

def smallest_number(*args):
print min(args)

def distance_from_zero(arg):
print abs(arg)

biggest_number(-10, -5, 5, 10)
smallest_number(-10, -5, 5, 10)
distance_from_zero(-10)


And this:


def biggest_number(*args):
print max(args)
return max(args)

def smallest_number(*args):
print min(args)
return min(args)

def distance_from_zero(arg):
print abs(arg)
return abs(arg)

biggest_number(-10, -5, 5, 10)
smallest_number(-10, -5, 5, 10)
distance_from_zero(-10)


In the end don't they give you the exactly the same answer.


#8

lets say i have a function:

def multiply(a,b):
   return a * b
result = multiply(4,2)

now i have the multiplication stored in a variable called result, instead of just printing, which mean i can use the result variable, or manipulate even further.

If a return keyword is reached, the function also ends. This can also be very useful if the function must make a logical decision.


#9

Am stuck at max() and min() can someone please explain further for me to understand better?


#10

#11

please make a new topic, this one is really old