+ 3

Is there any python specialist to help me?

My Problem is here. You are making a program to analyze text. Take the text as the first input and a letter as the second input, and output the frequency of that letter in the text as a whole percentage. Sample Input: hello l Sample Output: 40 The letter l appears 2 times in the text hello, which has 5 letters. So, the frequency would be (2/5)*100 = 40. My code is here: import math text = input() print(math.floor(100*text.count('s')/len(text))) But it shows only two test cases passes, others are fail.

10th Feb 2021, 9:56 AM
shafiq
shafiq - avatar
7 ответов
+ 8
You have to take 2 inputs , not 1 Analyze it - https://code.sololearn.com/cT98Beg30s40/?ref=app
10th Feb 2021, 10:07 AM
Abhiyantā
Abhiyantā - avatar
+ 4
Cyan "int and math.floot have the same effect" is only true for positive decimal numbers... for negative number you should use math.ceil: import math print(int(-42.6)) # -42 print(math.floor(-42.6)) # -43 print(math.ceil(-42.6)) # -42 ... but: print(math.ceil(42.6)) # -43
10th Feb 2021, 1:07 PM
visph
visph - avatar
+ 3
Cyan and visph thank you! Haha!
10th Feb 2021, 1:57 PM
Abhiyantā
Abhiyantā - avatar
+ 2
visph So int just removes the decimal but it does not mean it gets the floor of the number. I did not think of that and did not know about it. Thank You!
10th Feb 2021, 1:56 PM
noteve
noteve - avatar
+ 2
Cyan int truncate the float number floor get the nearest int under the float ceil get the nearest int above the float
10th Feb 2021, 1:58 PM
visph
visph - avatar
+ 1
Thanks to Rishav Tiwari & Cyan. Now code is working. There was mistakes about taking input.
10th Feb 2021, 12:06 PM
shafiq
shafiq - avatar
- 1
import math word = input() text = input() w = len(word) words =word.count(text) res = (words/w)*100 print(math.floor(res)
11th Feb 2021, 1:27 PM
Motuncoded
Motuncoded - avatar