+ 1

Could someone help me understand this code???

https://code.sololearn.com/cmq25Cy3Uk5L/?ref=app

16th Apr 2020, 6:41 PM
Soumya Singh
Soumya Singh - avatar
3 odpowiedzi
+ 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
16th Apr 2020, 8:44 PM
Jayakrishna 🇮🇳
+ 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..
16th Apr 2020, 8:08 PM
Jayakrishna 🇮🇳
+ 1
Actually I can't understood 34rth line ... ???
16th Apr 2020, 8:36 PM
Soumya Singh
Soumya Singh - avatar