+ 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/

28th Jul 2020, 7:32 AM
Arctic Fox
Arctic Fox - avatar
8 Antworten
+ 8
Yeah, I forgot 😅 By the way, thanks Abhay And Granger for helping
28th Jul 2020, 8:11 AM
Arctic Fox
Arctic Fox - avatar
+ 6
Granger Can't a whole file be lowered like: s=open(file.txt) s.lower() file.close()
28th Jul 2020, 8:07 AM
Arctic Fox
Arctic Fox - avatar
+ 5
Dragonxiv I want the def part of function and iteration of loop to be explained. Abhay Nope, I understood the concept but didn't got the working of code.
28th Jul 2020, 7:45 AM
Arctic Fox
Arctic Fox - avatar
+ 1
It is allready described in the lesson you have posted. What part you havw trouble with.
28th Jul 2020, 7:36 AM
Dragonxiv
Dragonxiv - avatar
+ 1
Than you should probably start with a more basic python tutorial
28th Jul 2020, 7:39 AM
Dragonxiv
Dragonxiv - avatar
28th Jul 2020, 8:05 AM
Abhay
Abhay - avatar
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
28th Jul 2020, 7:59 AM
Abhay
Abhay - avatar
- 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)
28th Jul 2020, 7:42 AM
Abhay
Abhay - avatar