-7

I get get this to work, and it seems simple but it wont.

bob = raw_input("What do you need?")
if bob is "Hello":
    sayhello()

def sayhello():
    print"yo"
ospahiu
  • 3,465
  • 2
  • 13
  • 24

3 Answers3

2

Use the value comparison operator instead ==, is checks for references (short answer I wrote on is, and its official doc).

def sayhello():
    print"yo"

bob = raw_input("What do you need?")
if bob == "Hello":
    sayhello()
Community
  • 1
  • 1
ospahiu
  • 3,465
  • 2
  • 13
  • 24
1

mrdomoboto has the solution for you. But a little background information is never bad.

is returns True if two variables point to the same object.

>>> a = [2, 3]
>>> b = a
>>> b is a 
True
>>> b == a
True
>>> b = a[:]
>>> b is a
False
>>> b == a
True
Peter234
  • 1,052
  • 7
  • 24
1

Your Problem is that You said "is" not ==. Also You have to define sayhello() before you use it. Also put brackets around print feature. You should also take away raw from input.

To fix this put in this code:

def sayhello():
    print ("yo")
bob = input("What do you need?")
if bob == "Hello":
    sayhello()