- 1
Loops count
Why the code not work properly https://code.sololearn.com/cI8302cDDwuA/?ref=app
4 Answers
+ 1
In the string "testing for loops", 't' occurs two times.
According to your loop, it searches for 't' in the string and whenever it encounters a 't', it increases the value of variable "count".
Now, with +=1, the value of "count" is 1+1 = 2. But, with +=9, the value of "count" is 9+9 = 18.
0
Because count starts at 0. There are 2 't's in your string. The for loop says: for each letter in the string, if the letter is 't', then take whatever count is and add 9 to it. 9 * 2 = 18
- 1
for x in str:
if(x == 'o'):
count += 1
so if I choose the word 'o', there's 3. so it's multiplied by 3 right? then the meaning of count += 1 I think only 1 is added
- 1
technically it adds or increments each iteration it finds a match. But yes