Python Forum

Full Version: If/Else Statement Help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
I am teaching myself python so sorry for the silly question. I wrote something very simple. If Joe calls, say "Hi Joe." If someone else calls say "How may I help?". Every time I will get back Hi, Joe regardless of the input. Can someone tell me what I am doing wrong? I am using Azure Notebooks:

friend = "Joe"
call = input("Who is this?")
if friend:
    print("Hi, Joe.")

else:
    print("How may I help?")

Ok dumb question. I forgot to insert

if call == friend
if friend Checks whether "friend" is True or not. In if statements, a non-empty string evaluets to True (conversely, empty string evaluates to False). That is why your if condition is always True.

Instead you probably want:
if call == friend