Friday, 13 September 2013

Python 'text analyzer'

Python 'text analyzer'

I'm just getting into Python and I'm building a program that analyzes a
group of words and returns how many times each letter appears in the text.
i.e 'A:10, B:3, C:5...etc'. So far it's working perfectly except that i am
looking for a way to condense the code so i'm not writing out each part of
the program 26 times. Here's what I mean..
print("Enter text to be analyzed: ")
message = input()
A = 0
b = 0
c = 0
...etc
for letter in message:
if letter == "a":
a += 1
if letter == "b":
b += 1
if letter == "c":
c += 1
...etc
print("A:", a, "B:", b, "C:", c...etc)

No comments:

Post a Comment