diff --git a/practica/stepik/stepik_tasks/percentage_of_letters.py b/practica/stepik/stepik_tasks/percentage_of_letters.py index dd6d323..c9b44e3 100644 --- a/practica/stepik/stepik_tasks/percentage_of_letters.py +++ b/practica/stepik/stepik_tasks/percentage_of_letters.py @@ -1,8 +1,31 @@ # процентное соотношение букв в строке S = input().lower() -print (S) +# print (S) g = S.count("g") -print (g) +# print (g) c = S.count("c") -print (g) -print (((int(g)+int(c))/len(S))*100) \ No newline at end of file +# print (g) +print (((int(g)+int(c))/len(S))*100) + + +# то же, но написать сколько встречается букв +s = str(input()) +l = len(s)-1 +c = 1 +t = '' +if len(s)==1: + t = t +s+str(c) +else: + for i in range(0,l): + if s[i]==s[i+1]: + c +=1 + elif s[i]!=s[i+1]: + t = t + s[i]+str(c) + c = 1 + for j in range(l,l+1): + if s[-1]==s[-2]: + t = t +s[j]+str(c) + elif s[-1]!=s[-2]: + t = t +s[j]+str(c) + c = 1 +print(t) \ No newline at end of file