Python Forum
Please tell me what i did wrong
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please tell me what i did wrong
#1
sample_list = [8, 2, 3, 0, 7]
print("Sample list: %s " % sample_list)

def sum_list(lists):
    for x in lists:
        total = total + lists[x]
    return total
    

print("Sum of all the number in the list: "),
print(sum_list(sample_list))

raw_input("\nPress ENTER to exit") 
 
I was told to create a function that can sum up all the elements in a list and this is what I came up with.
It didn't work
Please help
Reply


Messages In This Thread
Please tell me what i did wrong - by gabejohnsonny21 - Apr-20-2020, 04:09 AM
RE: Please tell me what i did wrong - by ndc85430 - Apr-20-2020, 04:41 AM
RE: Please tell me what i did wrong - by deanhystad - Apr-20-2020, 04:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong? Or is the question setup wrong? musicjoeyoung 3 2,774 May-18-2020, 03:38 PM
Last Post: musicjoeyoung

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020