Python how to sum a list
<p>I'm having trouble because I'm asking the user to input 6 numbers into a list and then total and average it depending on input from user. It's my HWK. Please help.</p>

<pre><code>x = 0
list = []
while x &lt; 6:
    user = int(input("Enter a number"))
    list.append(user)
    x = x + 1
numb = input("Do you want a total or average of numbers?")
numb1 = numb.lower
if numb1 == "total":
</code></pre>

<p>Here is my answer:</p>

<pre><code>def numberTest():
    global x, y, z
    L1 = []
    x = 0 
    y = 6
    z = 1
    while(x &lt; 6):
        try:
            user = int(input("Enter {0} more number(s)".format(y)))
            print("Your entered the number {0}".format(user))
            x += 1
            y -= 1
            L1.append(user)
        except ValueError:
            print("That isn't a number please try again.")
    while(z &gt; 0):
        numb = input("Type \"total\" for the total and \"average\"").lower()
        if(numb == "total"):
            a = sum(L1)
            print("Your total is {0}".format(a))
            z = 0
        elif(numb == "average"):
            b = sum(L1)/ len(L1)
            print("Your average is {0}".format(round(b)))
            z = 0
        else:
            print("Please try typing either \"total\" or \"average\".")
numberTest()
</code></pre>

<p>I tried this a couple of times and I know it works. If you are confused about parts of the code, I will add comments and answer further questions.</p>

python list sum average