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

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,659 Points

Python Functions Code Challenge 1

#TypeError: can't write str to text stream
#I used the Hands-On Python Tutorial Site for help with the code.
#nothing has been added to the list
sum = 0
#list is empty
add_list = []

#prompt for input
print("Type in some numbers please." )
print("Type DONE when you are finished.")

#function to show the total at the end
def show_sum():
  print("The total of your numbers is:")
  for sum in add_list:
      print(sum)

#main function to add up list of numbers while user inputs numbers the sum is increased 
def add_list(num):  
  while True:
    for num in add_list:
      num = input("> ")
      nextSum = sum + num
      sum = nextSum
      continue

#to stop the addition of the numbers
    if input == "DONE":
      break

#to show the final total
show_sum()
Nancy Melucci
Nancy Melucci
Courses Plus Student 36,659 Points

I don't know what the strange formatting is about. I am sorry because it seems to make it harder to follow. I hope you can still help me. I deleted and redid the post, it won't go away.

Hi Nancy,

See this thread for how to format your code: https://teamtreehouse.com/forum/posting-code-to-the-forum

I think what's happening is that all your python comments that begin with # are being treated as an <h1> using markdown syntax.

That should all go away once you can get the code posted properly.

Also, it's helpful to link to the challenge you're on.

Nancy, could you explain what your question is?

Nancy Melucci
Nancy Melucci
Courses Plus Student 36,659 Points

Sorry...when I try to add the second response (2 part code challenge) the first task is no longer passing....

def add_list(my_list): 
  total = 0
  for number in my_list: 
    total = sum(my_list)
    return total

The part above passes until I add this:

  def summarize(my_list):
    Str1 = " ".join[my_list]
  print "The sum of," Str1, "is", add_list(my_list), "."

and suddenly my first response is no longer passing and I get no useful feedback to help me debug the second part.

sorry for the delay. I work full time and I am taking "for credit" classes that need attention first.

thanks for your help.

Nancy M.

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Are you submitting this as a solution to the code challenge?

Code challenges don't take input() since they're not being run interactively.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Nancy Melucci Looking at your newest comment, you seem to have some indentation errors (the last line should be indented in compared to the def line above it) and you're using Python 2's print statement instead of Python 3's print() function. Since that's a SyntaxError, the code challenge runner isn't able to tell exactly where the mistake is, so it assumes step 1.