Last answered:

16 Aug 2021

Posted on:

14 Aug 2021

1

I was trying to solve the exercise but could not get the answer.

I tried doing the exercise but could not get the answer.





I am pasting my code, please let me know what is my mistake.

def count(numbers):
    total = 0
    while numbers[total] < 20:
        print (total =+ 1)
    return total

Also, why can't I use statements like

while x in nums:
  print total =+1
return total

Whats wrog with this code ?

1 answers ( 0 marked as helpful)
Instructor
Posted on:

16 Aug 2021

0

Hi Taufiq!

Thanks for reaching out.

In both examples, you are trying to increment a value (i.e. the value of 1) to a variable in the argument of a print function, while you need to do that outside the print function (still in the while loop). Please correct this and retry running the functions.

Hope this helps.
Best,
Martin

Submit an answer