Review Function: Result of Raw Input in a function


#1

Hi!

I have a question, here i want to use de result of the raw_input to respond de function argument.

How can i do this?

https://www.codecademy.com/es/courses/python-beginner-es-ACNhE/4/1?curriculum_id=50fc7aab5fab3aa9c2002444


respuesta = raw_input("Desea apagar la PC?")
s = respuesta.lower()

def apagado(s):
    if r=="si":
        return "Apagando..."
    elif r=="no" :
        return "¡Apagado cancelado!"
    else:
        return "Lo siento, no te entendí."

PD: srry for my inglish, i speak spanish hahahah !


#2

Hi there!
I'm not sure I understand the question.
Do you want to call the function using the users input?
If so you can just do:

apagado(input)

and that should use the input as a parameter.
Let me know if this didn't answer your question. :slight_smile:


#3

Yes, the idea is use de input as a parametrer to response, and print "Apagando..." etc.
And I cant.

It´s ok what i do?

def apagado(input):
    r=input.lower()
    if r=="si":
        return "Apagando..."
    elif r=="no":
        return "¡Apagado cancelado!"
    else:
        return "Lo siento, no te entendí."

raw_input("Desea apagar la PC?")

print apagado

#4

Hey there,

Your code is on the right track, but it isn't working the way you intended it to.
Below is the correct code. Notice how I stored the raw_input under a variable. That way I can make changes to it as necessary. Also, when I called the function, I called it using the built in python keyword: raw_input, as a parameter.
This should do what you wanted it to do. Let me know if it doesn't. Otherwise, have a great day!

def apagado(x):
r = raw_input("Desea apagar la PC?")
r = r.lower()
if r=="si":
print "Apagando..."
elif r=="no":
print "Apagado cancelado!"
else:
print "Lo siento, no te entendi."

apagado(raw_input)

Also for some strange reason. Using characters like í and ¡ prevent the code from working. Not sure why, but besides that, the code should work flawlessly :slight_smile:


#5

Thnx!!!

Now i understand the logic behind, thats was what i need.

:wink:


#6

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