Kevinvhengst Kevinvhengst - 1 month ago 7
Python Question

Printing one character at a time from a string, using the while loop

Im reading "Core Python Programming 2nd Edition", They ask me to print a string, one character at a time using a "while" loop.

I know how the while loop works, but for some reason i can not come up with an idea how to do this. I've been looking around, and only see examples using for loops.

So what i have to do:

user gives input:

text = raw_input("Give some input: ")

I know how to read out each piece of data from an array, but i can't remember anything how to do it to a string.

Now all i need is working while-loop, that prints every character of the string, one at a time.

i guess i've to use len(text), but i'm not 100% sure how to use it in this problem.

Some help would be awsome! I'm sure this is a very simple issue, but for some reason i cannot come up with it!

Thx in advance! :)


I'm quite sure, that the internet is full of python while-loops, but one example:


while i < len(text):
    print text[i]
    i += 1