0

I want to write a function that greets ‘Batman’ or ‘Black Widow’ in uppercase and all others in lowercase text.

def hello(name):
    if name == "Batman" or "Black Widow":
        print(f"Hello {name.upper()}")
    else:
        print(f"Hello {name.lower()}")
        
hello("Aqua Man")

Aqua Man should be all in lower but it shows as all upper

Here, Aqua Man should be all in lower but it shows as all upper. Can someone help me with this problem? Thank you!

En Xin
  • 929
  • 1
  • 6
  • 9

1 Answers1

1

The code you provided will always print "Hello AQUA MAN", because the if statement if name == "Batman" or "Black Widow" is always true.

The problem is that or "Black Widow" is not checking if the variable name is equal to "Black Widow", it is checking if the string "Black Widow" is truthy, which it is, because it is not empty.

To fix this you should change the if statement to if name == "Batman" or name == "Black Widow" so that both conditions are correctly evaluated.

Niemandx09
  • 39
  • 2