0

I have to take ascii values from characters in a paragraph and make them print like:

116 = t = (# of times it appears)

i have everything printing right except for the number of times it appears. I don't know what I am doing wrong with this counter.

any help appreciated

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by woooee
0
text = "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'  So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her."
    
i = 32

for x in text:
    count = 0
    while i <= 126:
        if x == chr(i):
             count += 1

        print i, "=", chr(i), "=", count
        i += 1
0

the 32 and 126 because im only dealing with characters in that value range from the ascii table

0

Print the value for "i" each time through the while() loop. And you should not use "i", "l", or "O" as single digit variable names as they can look like numbers.

for x in text:

Also the logic is bass-ackwards so print the value for "x" each time through the for() loop

for ctr in range(32, 126):
    for ltr in text:

Edited by woooee: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.