我在python中有一个元组:
tuple=(“aaa”,”aabc”,”aaara”,”aabsdaaa”)
我想编写一个函数来获取元组中的字符数:
Function((“aaammm”,”aabbcc”,”aaaera”,”aabbaaa”),”a”)
“Character “a” occurred maximum 5 times”
我写了一段代码,但它似乎没有正常工作......你能帮忙吗?
def function(tuple,character):
count=0
for ch in tuple:
if(ch==character):
count+=1
return count
print("the",character,"occured:",function(tuple,character),"times")