list1 = laughing.split('a')
#print(list1)
buffer1 = ''
n = -1
for each in list1:
if each != buffer1:
buffer1 = each
n += 1
return n
print(kooka_counter("HaHaHahahaHaHahaHahahahahaHaha")) 练习下,看看楼主的答案 def kooka_counter(d):
a = list(d)
c = 1
for i in range(1,int(len(a)/2)-1):
if a != a:
c += 1
del a
del a
print(c)
111 vioce=("hahahaHaHahaHaHahaha")
Temp=list(vioce)
if len(Temp)>0:
count = 1 #起始计数为1,是因为只要大于0就至少有1只
for i in range (0,len(Temp)-2):
if Temp != Temp:
count +=1
print(count)
else:
print("都没有鸟儿,哪里在唱歌")
hahahaha
import test
def kooka_counter(x):
if x == "" :
return 0
else:
y = 1
k = x
for i in range(2,len(x),2):
if x == k.swapcase():
y += 1
k = k.swapcase()
return y def kooka_counter(laughing):
k = 1
laughing = laughing.replace('a','')
if len(laughing)==0:
k-=1
for i in range(len(laughing)-1):
if laughing!=laughing:
k+=1
return k
print(kooka_counter("HahahahahaHaha")) 学习学习 本帖最后由 liujian973 于 2018-10-5 17:05 编辑
方法一:
def kooka_counter(laughing):
Ha = len()
ha = len()
return ha+Ha
方法二:
def kooka_counter(laughing):
import re
ha = re.findall("ha*",laughing)
Ha = re.findall("Ha*",laughing)
return len(ha+Ha) 6 def kooka_counter(laughing):
print (len(re.findall(r'(Ha)+', laughing)) + len(re.findall(r'(ha)+',laughing))) 666666666666666 import re
def kooka_counter(str1):
boys = re.findall(r'(Ha)+',str1)
girls = re.findall(r'(ha)+',str1)
return len(boys)+len(girls) A
import re
import test
def answer(strs):
boys = re.findall(r'(?:Ha)+', strs)
girls = re.findall(r'(?:ha)+', strs)
result = len(boys) + len(girls)
return result
answer('HaHaHahahaHaHa')
test.assert_equals(answer(""), 0)
test.assert_equals(answer("hahahahaha"), 1)
test.assert_equals(answer("hahahahahaHaHaHa"), 2)
test.assert_equals(answer("HaHaHahahaHaHa"), 3)
test.assert_equals(answer("hahahahahahahaHaHa"), 2) d 1 看答案
'''
这题算明天的。星期天来点简单的。
春天到了,树上的小鸟总是叫个不停。
男生叫起来'Ha',女生叫起来'ha',男生一句女生一句但是一句随便叫几声。
好了,现在请你根据叫声,算出有几只小鸟。
给出一个函数:def kooka_counter(laughing),返回小鸟的数量。
例如:HaHaHahahaHaHa分段为: 男 HaHaHa女 haha 男HaHa,所以这是3只。返回是3。
'''
'''
解题思路:
1、定义一个变量temp存在每次更新的叫声例如第一次为Ha,如果发现变化了那么temp= ha
2、定义一个变量count,每次temp变量就+1
'''
def kooka_counter(laughing):
temp = ''
count = 0
for i in range(0,len(laughing),2):
if temp != laughing:
temp = laughing
count += 1
return count
print(kooka_counter("hahahahahahahaHaHa")) 1
页:
1
[2]