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 (Retired) Putting the "Fun" Back in "Function" Functions

Rafael Pastrana
PLUS
Rafael Pastrana
Courses Plus Student 268 Points

EOFError

Hi, I'm doing a the Challenge Task 1 of Putting the "Fun" Back in "Function".

I made a working script in the shell but when I check the work in treehouse interface I get an EOFError.

Any thoughts on why this is happening?

Rafael

Rafael Pastrana
Rafael Pastrana
Courses Plus Student 268 Points

Code is:

number_list = []

def show_intro():
  print ("Please enter a list of numbers you want to sum.")
  print ("Enter 's' to calculate result.")

def append_list(num):
  number_list.append(num) 
  print ("Added! List has {} items.".format(len(number_list)))

def add_list(num):
  for num in number_list:
    sum(num)

def result():
  sum = 0
  for num in number_list:
       sum += int(num)
  print ("Sum is {}.".format(sum))

show_intro()

while True:
  new_num = input("> ")
  if new_num == 's':
    result()
    break
  else:
    append_list(new_num)

5 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Hmm, tested it again today and I get the same error.

Maybe it has something to do with you writing a whole script instead of just the needed functions? Your code definitely doesn't pass the requirements for the task. For example, your add_list doesn't add together all of the numbers of a list and return the total.

Rafael Pastrana
PLUS
Rafael Pastrana
Courses Plus Student 268 Points

Yeah, I haven't had time to check it out on more detail but assumed the problem had something to do with that. Any hints on how to tackle that issue? What about adding the "return" code line?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You don't need input() to pass any of my code challenges ;)

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Hmm, I don't get any errors with that code and don't see any mistakes in it (other than having a space between print and the parentheses).

Rafael Pastrana
PLUS
Rafael Pastrana
Courses Plus Student 268 Points

Hi Kenneth, thanks for your response. So do you think the error has something to do with the challenge interface? I really want to get over to the next one! :)

Rafael Pastrana
PLUS
Rafael Pastrana
Courses Plus Student 268 Points

Hi Kenneth,

I removed what was in the result function and put it in de add_list so that the latter actually adds together all of the numbers in the list. However, I pasted the script again and get again the EOF error.

Maybe it does have to do with writing a whole script. Any thoughts?

number_list = []

def show_intro():
  print ("Please enter a list of numbers you want to sum.")
  print ("Enter 's' to calculate result.")

def append_list(num):
  number_list.append(num) 
  print ("Added! List has {} items.".format(len(number_list)))

def add_list():
  sum = 0
  for num in number_list:
       sum += int(num)
  print ("Sum is {}.".format(sum))

show_intro()

while True:
  new_num = input("> ")
  if new_num == 's':
    add_list()
    break
  else:
    append_list(new_num)
Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Taking out the while True: gives more informative errors.

You're not required to write an interactive script to solve code challenges, just the required functions/etc. Take a smaller approach and see what that gets you.

Joseph Kato
Joseph Kato
35,340 Points

Isn't the EOFError related to the fact that the above script is making a call to input() but not receiving anything in return?