+ 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.
7 Antworten
+ 8
You have to take 2 inputs , not 1
Analyze it - https://code.sololearn.com/cT98Beg30s40/?ref=app
+ 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
+ 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!
+ 2
Cyan
int truncate the float number
floor get the nearest int under the float
ceil get the nearest int above the float
+ 1
Thanks to Rishav Tiwari & Cyan. Now code is working. There was mistakes about taking input.
- 1
import math
word = input()
text = input()
w = len(word)
words =word.count(text)
res = (words/w)*100
print(math.floor(res)