19/19 worked, but I have two important questions[SOLVED]


#1

Hello all,

on 19/19 Review:Built-In Functions my code worked, it passed. But I have an understanding question.
First, here is the code I used:


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

Two questions:

1.Why wouldn't it work if I put a number, instead of a word, for example def distance_from_zero(10):
When I try this, I get the error:
F"ile "python", line 1
def distance_from_zero(10):
^
SyntaxError: invalid syntax "

2.What should I do to get "Nope" as an output? Where should I "input" the type, so I can get something else than int or float?


#2
  1. It is uspposed to work when you put in a number hence the,
  1. To get the string "Nope"just input anything that isn't an integer or float. :slight_smile:

  2. When calling your function do not include the def just write,

outside of your function.

But a function parameter cannot be an integer.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.