DavidShefcik
DavidShefcik

Reputation: 45

Python: Even if the the if statement equals false it still executes the code inside the if statement

Even if the the if statement equals false it still executes the code inside the if statement. Here is the code:

# Imports:
import time

# Code Starts Here:
print("Welcome to a test application By: David(Toxicminibro)")
time.sleep(1.25)

Donald = "Donald Trump"
donald = "donald trump"
Hillary = "Hillary Clinton"
hillary = "hillary clinton"

name = input("What is your name?: ")

if name == Donald or donald or Hillary or hillary:
    print("No. Stop it.")
else:
    print("Hello " + name + " !")

Upvotes: 1

Views: 405

Answers (3)

LiavK
LiavK

Reputation: 752

A more Pythonic way of doing this is: if name.lower() in [donald, hillary]:

Upvotes: 1

Em L
Em L

Reputation: 328

if name in (Donald, donald, Hillary, hillary):
    print("No. Stop it.")
else:
    print("Hello " + name + " !")

Upvotes: 2

D Hydar
D Hydar

Reputation: 501

I think you mean to do :

if name == Donald or name == donald or name == Hillary or name == hillary:

Have a look at this link; it explains how various values are considered to be "true" or "false"

Upvotes: 2

Related Questions