+ 8
How the text analyzer actually works?
The working of text analyzer. The def function part and the iteration of loop I couldn't get my answer on search bar https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2457/
8 Antworten
+ 6
Granger
Can't a whole file be lowered like:
s=open(file.txt)
s.lower()
file.close()
+ 1
It is allready described in the lesson you have posted.
What part you havw trouble with.
+ 1
Than you should probably start with a more basic python tutorial
+ 1
𝙍𝙞𝙨𝙝𝙖𝙗𝙝«ℙ𝕪3» your welcome!
0
def count_char(text, char):
count = 0
for c in text:
if c == char:
count += 1
return count
So here suppose we call the function like
for char in "abcdef.....":
count_char(text,char)
So inside function first we check how many times "a" will occur ,=>count_char(text,"a")
Now for every character in text string we check if that character is equal to the letter "a" we passed as second argument ,if yes increment the count by 1 and when looping over text string finishes ,finally return the count variable which stores the value for how many times "a" occured ,and such happens for each letter ,so count_char function is called 26 times
- 1
It basically counts how many times each letter occurrred in text string that is read from file ,and calculates the percentage for each character like 100* occurrence of character /len(text)