gives me an error total reference before asignemt

product odf numbers

```
def product(numbers):
for n in numbers:
total *= int(n)
return total
```

gives me an error total reference before asignemt

product odf numbers

```
def product(numbers):
for n in numbers:
total *= int(n)
return total
```

this is a really smart way of doing it. My way was a bit more complicated:

```
def product(numbers): #Define a function
result = 0 #variable result set to 0
for i in numbers: # iterate through the the given list of numbers
if result != 0: # if the result is not 0
result = result * i # then multiply result by the number
else:
result = i #if not then set result to being the number
return result # return the result
```

but I can see now that I can could simply skip the entire part of my code that tries to make sure you don't multiply by 0 the first time by just setting the variable, my case 'result', to 1.

so thank you for this,

hope my logic here helps someone as well.

the good thing on coding is the freedom to do it your on way,

i see this code in the forum and adapeted to me .

yours is also good ,it works that's what matters

what i have learn is if you can make your program with less lines better

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.