Python Python Basics Functions and Looping Create a Function

4,333 Points

EOF error in challenge, code runs fine in workspace

So I saw another post regarding a similar problem that didn't answer my question so here's mine.

"Create a function named square. It should define a single parameter named number.

In the body of the function return the square of the value passed in."

From what I could tell, and running it seems to do what the question's asking for. I created the function named square, defining only a single parameter named number, and return the square of the value passed in by the users input. Oddly it passes the first test ok, and the second one returns the EOF error. Maybe there's a different way it's wanting me to do things and I'm just misunderstanding the ask in this particular challenge?
import math

def square (number):
    return math.ceil(number * number)

number = float(input("What number would you like to square?  "))

squared = square(number)

print ("Your number squared equals {}".format(squared))

2 Answers

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

Hi there, horus93 ! I can see that you've worked hard on this and you're doing great. But keep in mind that these challenges aren't a full-fledged program. Treehouse is going to call that function and send in a number. They expect to get back the result of that number squared. Doing things like using an input will likely cause the challenge to break. Remember, there's no one on the other side to input anything. You've also printed out the result and formatted it neatly, but again, this was not asked for by the challenge. Doing things that are not asked for can cause the challenge to break even if they are functional outside of the challenge.

Here's a list of things you will not need:

  • the import of the math library
  • math.ceil
  • a print statement
  • an input statement

You will also need to change the squared variable to result as asked for in the second step. In that step, you will send in a concrete number like 10 or 7 instead of trying to get the number from the user.

Mainly, the problem here lies in doing things that are not asked for by the challenge. I feel like you can get it with these tips, but let me know if you're still stuck! :sparkles:

4,333 Points

Haha thanks, as usual I was over thinking things, and after a day of work I came home with my brain too tired to process things properly (for some reason I was scanning over the word "not" in your list of things I would not need, and just reading it as "Here's a list of things you will need", so basically slapping my head against a wall until I reread your post this morning and fixed the issue allowing me to continue onward and upward!

Thanks Jennifer!