-3

So I have this code:

welcome = input()
if (welcome.lower() == "Hello") or (welcome.lower() == "Hey") or (welcome.lower() == "Hej"):
    input("Hello,\n" + "my name is Misty.")
else:
    print ("That way of saying hello is new to me, should i save it in my memory?")

Why does this code not write hello back to me when I write lowercased Hello, Hey and Hej?

vaultah
  • 44,105
  • 12
  • 114
  • 143
Mads
  • 1

2 Answers2

4

lower will convert all of the letters in a string to lower-case. Therefore, they will never compare equally to "Hello", "Hey", or "Hej" as each of those strings start with 1 uppercase letter.

Instead try

if welcome.lower() in ('hello', 'hey', 'hej'):
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
0

That is because welcome.lower() can't be "Hello" really.

The purpose of lower() is to make the string all lowercase.

So, change like that:

if (welcome.lower() == "hello") or (welcome.lower() == "hey") or (welcome.lower() == "hej"):
Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57
  • thanks all of you, but what if i want to have it say the same to hello and Hello and so on? so that even if you write it uppercase or lover case it will stil say the same back? – Mads Oct 08 '15 at 07:33
  • cast every input to either `uppercase` or `lowercase` and then compare with `hello` and `HELLO` respectively. Both ways will work. – Ahsanul Haque Oct 08 '15 at 08:50