Steve Young
Steve Young

Reputation: 19

unexpected line 1 syntaxError:

I've got an error I cant figure out, the code is:

def distance_from_zero(6):
    if type(6) == int or type(6) == float:
        return abs(6):
    else:
        return "Nope"

and I'm getting this error:

File "python", line 1
def distance_from_zero(6):
                       ^

SyntaxError: invalid syntax

I cant figure out why ('number'): would be wrong, It's probably something simple but any help would be great. Thanks in advance

Upvotes: 1

Views: 144

Answers (1)

Rahn
Rahn

Reputation: 5405

Name the argument, not a specific number.

def distance_from_zero(num):
    if type(num) == int or type(num) == float:
        return abs(num)
    else:
        return "Nope"

Upvotes: 2

Related Questions