New course! Every coder should learn Generative AI!
Try a free lesson0
text analyzer
The round function in the text analyzer code reduces the number of digits printed. Why is it not to make the result more precise? Below is the code; for char in "abcdefghijklmnopqrstuvwxyz": perc = 100 * count_char(text, char) / len(text) print("{0} - {1}%".format(char, round(perc, 2)))
1 Answer
+ 8
You should leave the original value as a float and format the string output adequately, specifying the after-comma precision there. That gives better result most often.