-3

I would like to learn how could i run below Python code proper way. I guess comments will do the work below. Now, this only works well just in case I type "True" or "False" with capital initial letters. But I also need to get the same result when typed 1 or true etc.

# Here we ask the user place an input and assign it to name parameter.
name = raw_input ("What is your name human?: ")

# Here we will display the value of name parameter placed by user
print "Got it! Your name is %r" % name

# Here we ask the user if he is owning the device.  
# We will assign the answer to computers_owner parameter
computers_owner = input ("Are you the owner of this machine?: ")

# In this question's answer we have an if condition.

# If the answer is True machine will say "Good! I need you" % name
if computers_owner is True:
    print "Good! I need you %s" % name  

# If the answer is False machine will say "Call me your master!" % name 
else:
    print "Call me your master! %s" % name 
Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
phantomxxx
  • 15
  • 1
  • 3
  • Use `raw_input()` in second input as well and compare like this: `computers_owner.lower() == "true"` – Mohammad Yusuf Jan 02 '17 at 19:29
  • And add more conditions as you mention so `computers_owner.lower() == 'true' or computers_owner.lower() == 'y' or computers_owner == 1`. You get the idea. – gold_cy Jan 02 '17 at 19:31
  • 1
    Why would a user expect to be *able* to enter `1` as the answer to a yes/no question? Just check for a string that starts (case ignored) with `y` or `n` and be done with it. – chepner Jan 02 '17 at 19:34

1 Answers1

3

You can use a list for true conditions like this:

name = raw_input ("What is your name human?: ")
print "Got it! Your name is %r" % name
computers_owner = raw_input("Are you the owner of this machine?: ")
if computers_owner in ['1','yea','y','yo','hell yeah','true','True', 'true dat']:
    print "Good! I need you %s" % name  
else:
    print "Call me your master! %s" % name 
Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78