+ 1

can anyone help me to Slove this please?

https://www.sololearn.com/coach/73?ref=app import math as m word=str(input()) a=word.split() n =0 b=list(a) d=len(b) for i in b: n+=len(i) n=n/d print(m.ceil(n))

15th Aug 2020, 10:39 AM
Strange
Strange - avatar
3 odpowiedzi
+ 7
Strange , befor asking for help, you are requested to present your attempt first. Please put it in playground and link it here. Thanks!
15th Aug 2020, 11:22 AM
Lothar
Lothar - avatar
+ 2
phrase = input("") words=0 letters = 0 for i in phrase: if i == ' ': words+=1 elif i != '?' and i != ' ': letters+=1 words += 1 avg = letters/words avg2 = int(avg) if avg2 < avg: avg2+=1 print(avg2)
15th Aug 2020, 10:44 AM
Abhay
Abhay - avatar
+ 2
I don't know if it's the most efficient solution but here is how I would have solved this problem. # inputing the string string = input() # importing ceil function from math module to round up to the nearest whole number from math import ceil # the number of words is the length of the list generated when the string is split by spaces words = len(string.split()) # setting letters to zero letters = 0 # getting each character in the string for char in string: # checking if it is an alphabet if char.isalpha(): # incrementing letters by 1 letters += 1 # the average is the number of letters divided by the total number of words average = letters / words # printing the average rounded up to the nearest whole number print(ceil(average))
17th Aug 2020, 2:32 PM
Ali Shah Jindani
Ali Shah Jindani - avatar