|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def fun(program):
length = len(program)
for i in range(length):
letters = 0
space = 0
digit = 0
others = 0
for each in program[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)):
fun('i love fish.com. i love you,you love me.')
请问哪有错误么?为什么老是运行不了呢?
先帮你改正粗心导致的问题:
- def fun(program):
- length = len(program)
- for i in range(length):
- letters = 0
- space = 0
- digit = 0
- others = 0
- for each in program[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))
复制代码
主要是有两个小括号写成了中文的符号,以及最后多写了一个冒号。
但这个程序还不能实现目的,你研究下为什么?
|
|