Skip to content

Instantly share code, notes, and snippets.

@wohhie
Created July 25, 2016 17:38
Show Gist options
  • Save wohhie/3f7cea62bd498d85a8a7fca0cd62deee to your computer and use it in GitHub Desktop.
Save wohhie/3f7cea62bd498d85a8a7fca0cd62deee to your computer and use it in GitHub Desktop.
❋print pecentage
#count_char method.
#which count the total value
def count_char(text, char):
count = 0
for c in text:
if( c == char):
count += 1
return count;
#insert filename
filename = str(raw_input("Enter filename: "))
#read data
with open(filename) as data:
text = data.read();
#print data
#print(text);
#search for the value
count = str(count_char(text, "v"))
print("Counted value: " + count)
#print pecentage
for char in "abcdefghijklmnopqrstuvwxyz":
percentage = 100 * count_char(text, char) / len(text)
print("{0} = {1}%" .format(char, round(percentage, 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment