|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么我的程序运行不出正确的结果?
#我的程序
def count(string):
length = len(string)
for each in range(length):
letter = 0
number = 0
space = 0
otherstring = 0
if type(each) == str:
letter += 1
elif type(each) == int:
number += 1
elif each == ' ':
space += 1
else:
otherstring += 1
print("""第1个字符串中共有:英文字母%d个,数字%d个,空格%d个,其它字符%d
个"""%(letter,number,space,otherstring))
count("I Love You,You LOve Me.")
#小甲鱼的程序
def count(*param):
length = len(param)
for i in range(length):
letters = 0
space = 0
digit = 0
others = 0
for each in param[i]:
if each.isalpha():
letters += 1
elif each.isdigit():
digit += 1
elif each == ' ':
space += 1
else:
others += 1
print('第 %d 个字符串共有:英文字母 %d 个,数字 %d 个,空格 %d 个,其他字符 %d 个。' % (i+1, letters, digit, space, others))
count('I love fishc.com.', 'I love you, you love me.')
|
|