2
I have a little trouble understanding while
and I came across an exercise that asked me to do the following:
Read N sequences and find out how many f has in each sequence. I cannot use for
in that matter.
My code went like this:
i = 0
faltas = 0
while True:
registros = raw_input()
if registros == '-':
break
while i < len(registros):
if registros[i] == 'f':
faltas += 1
i += 1
print faltas
The problem is that if I type a sequence that has less 'f’s than the previous one it does not show the amount of gaps in the sequence.
Ex:
.f.f.f.f
faltas = 4
.f.f..
faltas = 4 (onde deveria imprimir 2)
Can you read the while ? syntax, make sure it helps you understand https://answall.com/questions/220915/help-loop-while-em-python
– Luiz Augusto
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero