A
A
anton_zaboev2021-11-23 18:12:41
Python
anton_zaboev, 2021-11-23 18:12:41

Why is there only 1 iteration?

Good afternoon! I’m solving such a problem 619d0370542e5273983934.jpeg
and I can’t figure out why after checking only one iteration passes for me
here is a link to the code
When an empty list is received, everything works fine, but when the list is not empty

if numbers:
        for item in numbers:
            count_respondents += 1
            if int(item) in range(9, 11):
                promoter += 1
            elif int(item) in range(0, 7):
                critic += 1

            nps = round((promoter - critic)/count_respondents*100)
            return nps
then for some reason only 1 iteration passes and the code does not work out to the end and as a result it does not count correctly.
Please tell me what I'm doing wrong and why only one iteration passes if there is more than 1 in the list of elements?for item in numbers:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2021-11-23
@anton_zaboev

You enter the loop for item in numbers:with the first value of your array (10). You check / change something there and exit the function by return. All.
I can only assume that it return npshas the wrong indentation. Check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question