Eric MaranguPython Web Development Techdegree Student 730 Points
I need help with the typeError.
I have a challenge with getting the code right in the Even or Odd quiz. Can someone guide me on what i'm doing wrong.
def even_odd(): number = int(input("Please enter a number: ")) workout == number % 2 if workout == 0: print("True") elif workout == 1: print("False")
Chris HowellPython Web Development Techdegree Graduate 49,485 Points
You are getting a TypeError because the challenge asks you to
Write a function named even_odd that takes a single argument, a number.
Now you did define the function even_odd but yours takes no parameters.
Your type error is actually hinting at this issue.
Bummer! TypeError: even_odd() takes 0 positional arguments but 1 was given
A test is run against the function you write and that test provides the parameter that is passed in. So you have to allow parameters to be passed into your function. It only asks for 1. You wont need to type to get user input using input() the test passes the parameter into the function, you cannot override that behavior. :)
Also the challenge asks you to return True or return False, you are using print which works for printing to a terminal but isnt used in most code challenges. Unless it explicitly asks you to. Most of the time you will be returning things from your function.
Hope that helps :)