+ 1
Could someone help me understand this code???
3 Antworten
+ 1
for char in "abcdefghijklmnopqrstuvwxyz":
perc = 100 * count_char(text, char) / len(text)
print("{0} - {1}%".format(char, round(perc, 2)))
There {0} is replaced by 0th position value thar char. It's like 0 is index per parameters in format function
And {1} is replaced by round(perc, 2), this return perc calculated value in previous line is rounded to 2 decimal points.. Check changi G to 3, or 4 will result to 3 or 4 decimal points like 0.123 or 0.1234 for example.
Which is same as
print(char, " - ", round(perc, 2),"%", sep="")
Check by replacing this by last line
+ 1
Which lines you don't understand here.. Specify that pls...
file = open("newfile.txt", "w")
file.write("""abcd efghij """)
file.close()
#There first creating a file in write mode with some text, and closing.
filename = "newfile.txt"
with open(filename) as f:
text = f.read()
#Again opening same file with read mode, reading into text variable. and with the help of function count_char it calculating a to z characters percentage exists in that text..
+ 1
Actually I can't understood 34rth line ... ???