Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Number Game App Even or Odd

Eric Marangu
seal-mask
.a{fill-rule:evenodd;}techdegree
Eric Marangu
Python 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.

even.py
def even_odd():
    number = int(input("Please enter a number: "))
    workout == number % 2
    if workout == 0:
        print("True")
    elif workout == 1:
        print("False")

1 Answer

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 :)

Awesome man! Glad it helped!