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

mahesh gurbaxani
mahesh gurbaxani
1,420 Points

where have I gone wrong?

Please help.Thanks

functions.py
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.
number_list=list()
def show_num():
  print("whats your number or 0 to quit")

def add_list(new_num):
        number_list.append(new_num)
def show_total():
         for new_num in number_list:
          new_num+=num
         print(num)

while True:

        if new_num == "0":
         show_total()
        break


        add_list(new_num)
continue

        show_num()
Joshua Ferdaszewski
Joshua Ferdaszewski
12,716 Points

One thing that I see right away is that you have issues with indentation and white space. Spaces/tabs hold syntactic importance in Python, as they show what parts of your code are in specific function or while loops for example. Looking at your code it is not apparent what this program is trying to accomplish.

1 Answer

I think at the beginning you are trying to initialize a new list? If so, you should do that like this:

number_list = []

Also, your function names don't seem to line up with what the functions are actually doing. For example, your function show_num seems like it should print a number to the console, but instead you ask the user for a number, and then don't follow up with a way for the user to input a number.

You are also missing the function "summarize" which should "sum up" what your add_list function just did...

It seems like the while loop is also unnecessary for this assignment.