print "Is Lelis on-line ?"
hi there.. sorry i'm late
ok. Vamos passar para português ou para crioulo ?
this should be in english right? for others to understand and join us if they want to
##Estava aqui a lutar com uma cobra \o/ raw_input("Is Lelis Online ? Answer True or False : ") ##até aqui tudo bem. Depois definir uma função e é aqui que tudo tranca def Is_Lelis_Online(): return "Hi! Desculpa o atraso; ainda podemos fazer algo?"
If someone copies your code from OpenStudy to paste it into a Python and try it, it will fail to copy properly. If you use dpaste, pastebin, or gitgub's gist, you can share code that saves the proper formatting.
yes indentation is important.. have to be careful about it. but in this case i worked just fine for me. But i need further explanation on what you are trying to accomplish here.
## I was figthng with Python code raw_input("Is Lelis Online ? Answer True or False : ") ## since here ok. Now definnig a function and here I get stunk def Is_Lelis_Online(): return "Hi! Desculpa o atraso; ainda podemos fazer algo?"
Ok. if I type True (or yes) the function return a string, elif you type False (or no) return another string and any case else a third string. But I fall in a infinite loop.
Thanks senior e. mccormick
It would be useful to see the loop in question. Also, are you testing for "True" == string or "true" == string.lower(). The .lower() can help a lot with these type tests.
you want your function to behave when given a certain input, i'm i understanding you right? So first your raw_input statement must be part of the function. Then after receiving the client input you will deal with it (may using decision control like if, elif and else)
I didn't write the code because of the infinite loop, but here it is If you think the error is too obvious, make me think first; " por favor." raw_input("Is Lelis Online ? Answer True or False : ") def is_Lelis_Online(bool): if is_Lelis_Online(bool)== True: return "Hi! Desculpa o atraso; ainda podemos fazer algo?" elif is_Lelis_Online(bool) == False: return "Sorry! I totally forget you. Muito contente por encontrar um crioulo. Keep in touch." else: return "Just answer 'True' or 'False'" print is_Lelis_Online(bool)
What are you doing with the return from the raw_input?
The raw_input function takes in text from the user and assigns it to a string. Once you have that string, you can do things with it. In this case, you want to turn that into a bool and based on the bool, print a message. Also, there is no need for the recursive call for this. That is what is causing an infinite loop.
Ok to both. Need some time to try to understand the intructions and the hints.
good!
i'm sorry , i've deleted my message because i wanted to correct some misspelled but i forgot to save it. But i'm sure now you understand what to do with mccormick explanations and also mine.
In psudicode (pretend programming) this is what you need to do: Get input from user and assign it to a string. Test the input and see if it is useful or not. If it is useful, decide if Lelis is online or not and print message. If it is NOT useful, repeat prompt to user. By following those four basic steps, you should be able to do what you want. The below link leads to a solution to your problem. NOTE: It is a little advanced! If you finally give up, this is one way to solve it. However, what I do with a dictionary is what most people would use an if/elif/else chain to do. I do not expect you to fully understand this solution at this time. However, it will give you something to think about. http://pastebin.com/tFGGvEum
""" Ok. A litle walk to breed; Now in else case I wont to repeat the question but I didn't see how. """ s = raw_input("Is Lelis Online ? Answer 'yes' or 'no' : ") def is_Lelis_Online(s): if s == 'yes': return "Hi! Desculpa o atraso; ainda podemos fazer algo?" elif s == 'no': return "Sorry! I totally forget you. Muito contente por encontrar um crioulo. Keep in touch." else: return "Just answer 'yes' or 'no'" print is_Lelis_Online(s)
Much better looking.
What you did works fine. It does not loop over the question, but it does give a valid answer! Very good! Now take a look at the version I did. It is a little different. It also works for a wider range of answers and does not care about capitol letters, so Yes, yes, yEs, and yeS all work!
##can I put an if in the else case ? s = raw_input("Is Lelis Online ? Answer 'yes' or 'no' : ") def is_Lelis_Online(s): if s.lower() == 'yes': return "Hi! Desculpa o atraso; ainda podemos fazer algo?" elif s.lower() == 'no': return "Sorry! I totally forget you. Muito contente por encontrar um crioulo. Keep in touch." else: return raw_input("Just answer 'yes' or 'no'! Is Lelis Online ?: ") print is_Lelis_Online(s)
Yes, you could change what I did to use if/else. It is not that different.
For a valid answer check it is basically: answer="" while answer=="" answer=raw_input answer=answer.lower() if answer=="true1" or answer=="true2": print true response elif answer=="false1" or answer=="false2": print false response else: answer="" print invalid input message Then it stays in the while loop until it gets a valid input.
Note that in that psudocode, the else restes the answer to "". This keeps it in the loop until they give a valid answer. The prints could also be returns if this was in a function.
I got it and will pratice during the Week. Hope to find you both here, next weekend. It was a nice expriment.
Have fun!
Join our real-time social learning platform and learn together with your friends!