Jan-20-2019, 01:12 PM
So this was the question description :
# Write a Python function to sum all the numbers in a list.
# Sample List : (8, 2, 3, 0, 7)
# Expected Output : 20
This is my code :
# Write a Python function to sum all the numbers in a list.
# Sample List : (8, 2, 3, 0, 7)
# Expected Output : 20
This is my code :
lst = [] i = 0 sum = 0 print ("Enter how many numbers:") x = input() while i < int(x): print ("Enter number: ") y = input() lst.append(y) i = i + 1 def sum(): for i in range(x-1): sum = lst[i] + sum i = i + 1 print ("sum")When I tried to run the code in my terminal, I got the prompt to enter how many numbers there were in the list and also the prompt to enter the individual numbers. However, the code ends there immediately ... it doesn't print out the sum of the numbers. What am I missing, please advise thanks alot !