Created
July 25, 2016 17:38
-
-
Save wohhie/3f7cea62bd498d85a8a7fca0cd62deee to your computer and use it in GitHub Desktop.
❋print pecentage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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