0

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)))

8th Aug 2018, 4:11 AM
AHMAD MUHAMMAD OTHMAN
AHMAD MUHAMMAD OTHMAN - avatar
1 Réponse
+ 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.
8th Aug 2018, 6:42 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar