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 trialTaha Ansari
1,318 PointsWhy am I getting an EOF error; my code should be working?
def square(number):
return (number* number)
number = int(input("what is the number"))
total = square(number)
print ("the square root is" .format(total))
1 Answer
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi Taha,
I think the EOF error is not your error. The EOF error is the error by the test script that’s used to evaluate your code. You see, you’re asking for user input, but the challenge doesn’t instruct you to ask for user input. The challenge doesn’t instruct you to seek user input because the test script that’s meant to evaluate your code is not going to pass in any user input. So when the test encounters code that says, “Hey, what is the number?”, it ends up reaching the end of its testing script prematurely.
The second challenge only asks you to call your square function, pass in the number 3 as an argument, and assign it to the variable result, so that the square of 3 is stored in the variable. All of that is meant to be written in one line.
In this case, by not following the specific instructions, you’ve encountered an error. In addition, in this statement:
print ("the square root is" .format(total))
You shouldn’t have a space between print and the parens, you shouldn’t have a space between the end of your string and the dot format (.format(total) method, and in order to pass the value of total into the string you would need to add “{}” open and closing curly braces inside your string so that python knows where to sub in your value.
That said, none of that code is necessary for this challenge. The same goes for number variable declaration and the total variable declaration. Neither of those statements are necessary to your code, and keeping them causes the test for the challenge to behave in unexpected ways.
I hope that helps. Good luck going forward. :)
Taha Ansari
1,318 PointsTaha Ansari
1,318 PointsThanks so much Brandon; I realized finally that I was adding too much unnecessary code for the task assigned. I fixed it and it works now.