Hi, I have just recently started using python and I couldn't figure out two problems regarding finding the first three occurrences of spaces using while loops. I have trouble understanding the concept of while loops.
How would i write a program that reports the first three occurrences of a space, using a while loop. Assume that there will be at least three spaces in the string. Any string with fewer than 3 spaces is considered invalid input, and so the program is allowed to function improperly.
what i tried and got was:
s=raw_input('Enter a string: ')
position=0
while i < len(s):
if s==' ':
position = position + 1
print 'There is a space in position ' + str(position)
Second:
I have modify the previous program so that it does not give an error if there are fewer than three spaces in the string but otherwise behaves the same.