0

My python code wont work for some reason. It says the error is coming from the syntax of the function but im not sure why its doing that

one=1
two=2
three=3
four=4
five=5
six=6
seven=7
eight=8
nine=9
ten=10
print "test"
def convert()
  number = raw_input('Enter the number you need converted to binary')
enterYourCommand = raw_input("Enter your command")
if enterYourCommand is "convert"
  convert()
elif enterYourCommand is "tonumber"
  tonumber()

3 Answers3

1

You don't have : after function definition and if's:

one=1
two=2
three=3
four=4
five=5
six=6
seven=7
eight=8
nine=9
ten=10
print "test"

def convert():
  number = raw_input('Enter the number you need converted to binary')

enterYourCommand = raw_input("Enter your command")

if enterYourCommand is "convert":
  convert()
elif enterYourCommand is "tonumber":
  tonumber()
Tomáš Jacík
  • 645
  • 4
  • 12
0

You missed the colons after if, elif and def. You have to indent with four spaces. See this link for examples.

one = 1
two = 2
three = 3
four = 4
five = 5
six = 6
seven = 7
eight = 8
nine = 9
ten = 10

enterYourCommand = raw_input("Enter your command")

def convert():
    number = raw_input('Enter the number you need converted to binary')

if enterYourCommand == "convert":
    convert()
elif enterYourCommand == "tonumber":
    tonumber()

Hope it helps.

EDIT

Replace is with ==.

  • is will return True if two variables point to the same object
  • == will return True if the objects referred to by the variables are equal.

Sources : is-there-a-difference-between-and-is-in-python

Community
  • 1
  • 1
JazZ
  • 4,469
  • 2
  • 20
  • 40
  • It doesnt have anymore errors but when i enter convert as raw input its asking me for the if statement doesnt detect it and do the convert function. Any ideas why? – Kody Simpson Aug 30 '16 at 19:11
  • See the edited answer. It uses `==` instead of `is` to get it work. – JazZ Aug 30 '16 at 20:00
0

All python functions should have a colon : at the end of their declaration line.

For example:

    def convert():
        number = raw_input('Enter the number you need converted to binary')

Also, the same is with your if and elif declarations:

    if enterYourCommand is "convert":
        convert()
    elif enterYourCommand is "tonumber":
        tonumber()

So, just add : at the end of each declaration and you should be good to go.

mayankchutani
  • 273
  • 3
  • 14