Hi everyone once again!
I’m dealing with this assigned string to a variable:
if isard == ‘espantar-los’:
I was just wondering if it will be possible to assign more possible string as raw_input() like this:
if isard == ‘espantar-los’ or ‘Espantar-los’:
Thank you so much once again,
Yes you can.
But you have to do like this:
animal = input(”>”)
If animal == ”cat” or if animal == ”dog”:
print(”Yes it is an animal!”)
In your example, maybe think about converting whatever you receive into lower or uppercase first. Then you don’t need to check both formatting examples.
Hi @ulfen69, your answer for @Ricard is close, but you have an additional if:
if animal == "cat" or animal == "dog":
print("Yes it is an animal.")
Additionally, @Ricard this is covered when you get to the logic drills later. You can combine any tests into a string of logic using
and keywords. I believe that’s the next few exercises in the book.
I hope I did not mislead you with my answer.
@gpkesley 's answer was much better for your question.
I did not see the only difference was just a uppercase letter in the second snippet.
I hurried on this one. I’m sorry
Thank you so much for helping me. You guys rock!
I tried what @zedshaw explains and it worked perfectly! I’m looking forward for the next exercises in the book but now I’m trying to make this game (ex.36) a little bit harder that what I thought it would be in the beggining, just to practise more! This takes me time in problems like this things with raw inputs.
By the way @gpkesley, which would be one possible way of do the conversion to lower or uppercase first? I don’t know how to do it. Is there any .lowercase or .uppercase that only works for the first letter (in this case)?
Thank you so much once again, this forum is awesome and the summation of the book and the community is just making me more and more interested in programming.
It’s worth reading up on string methods but .upper() and .lower() are pretty straightforward.
Try something like this:
if isard.lower() == ‘espantar-los’:
That way the input could be ‘eSPanTAr-LOs’ and it would still work.
Thank you Graham! I read the strings methods and I understood your correccion perfectly. That was what I was looking for since the beginning.