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 trialmahesh gurbaxani
1,420 PointsHow does one accept numbers without using the "input" function.
How does one accept numbers without using the "input " function. Is the rest of this code okay?
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: bonum_list=list()th functions will only take *one* argument each.
num_list=list()
def add_list():
while True:
num=int(input("> "))
if num==0:
break
add_item()
else:
num_list.append(num)
def add_item():
for number in num_list:
print(number)
num+=num
print(number)
add_list()
2 Answers
shezazr
8,275 PointsYou are doing it a bit wrong.
your functions will get an arguement which is a list. You just have to loop through and add it to another variable called sum/total and return that..
Kenneth Love
Treehouse Guest TeacherFunctions can receive arguments. We set this up when we define the argument:
def my_function(my_argument):
print(my_argument
Now when I call my_function
and give it an argument: my_function(5)
, it'll print the argument. In this case, the number 5. Arguments can be any Python type and you don't specify the type when you create the function.