|
3鱼币
本帖最后由 香喷喷的咸鱼 于 2021-1-14 15:46 编辑
- def Other_code (str1): #这个函数实际多此一举了,但是多练习一下!
- length=len(str1)
- i=0
- for each in range(length-1):
- if str1 not in (num and space and word):
- i+=1
- return i
-
- def text (*params):
- length1=len(params)
- for each in range(length1-1):
- num1=0;word1=0;space1=0;other1=0
- for each1 in params[each]:
- if params[each][each1] in num: #此处我想通过索引each得到元组内第几个字符串。再利用each1得到字符串内的第几个元素。不知道是否可以
- num1+=1
- elif params[each][each1] in space:
- space1+=1
- elif params[each][each1] in word:
- word1+=1
- other1=Other_code (params[each])
- print('第%d个字符串共有:英文字母%d个,数字%d个,空格%d个,其他字符%d个。'%(each,word1,num1,space,other1))
- num=r'0123456789'
- space=r' '
- word=r'qwertyuiopasdfghjklzxcvbnm'
- text('I love fishc.com.', 'I love you, you love me.')
复制代码
以上是我的程序,有错误不能正常运行 但又不知道哪些不太合理。希望热心的鱼油可以帮我解惑!
咸鱼在此感激不尽!
- def Other_code (str1): #这个函数实际多此一举了,但是多练习一下!
- length=len(str1)
- i=0
- for each in range(length-1):
- if str1 not in (num and space and word):
- i+=1
- return i
-
- def text (*params):
- length1=len(params)
- for each in range(length1):
- num1=0;word1=0;space1=0;other1=0
- for each1 in params[each]:
- if each1 in num: #此处我想通过索引each得到元组内第几个字符串。再利用each1得到字符串内的第几个元素。不知道是否可以
- num1+=1
- elif each1 in space:
- space1+=1
- elif each1 in word:
- word1+=1
- other1=len(params[each])-num1-word1-space1
- print('第%s个字符串共有:英文字母%s个,数字%s个,空格%s个,其他字符%s个。'%(each+1,word1,num1,space1,other1))
- num=r'0123456789'
- space=r' '
- word=r'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
- text('I love fishc.com.', 'I love you, you love me.')
复制代码
|
-
-
|