|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
是因为*params导致的吗?
代码一:
def count(*params):
yingwen = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz'
shuzi = '0123456789'
kongge = ' '
zifu = '!~@#$%^&*()_{}[]?/|\<>,.`;:'
l = len(params)
print(l)
print(params)
for i in range(l):
s1=s2=s3=s4=0
for each in params[i]:
if each in yingwen:
s1 += 1
if each in shuzi:
s2 += 1
if each in kongge:
s3 += 1
if each in zifu:
s4 += 1
#print('第%d个字符串共有:英文字母%d个,数字%d个,空格%d个,其他字符%d个.'%(i+1,s1,s2,s3,s4))
print('请传入字符串参数:',end = '')
#params = eval(input())
params = input()
count(*params)
输出:
请传入字符串参数:('I love fishc.com.','I love you,you love me')
46
('(', "'", 'I', ' ', 'l', 'o', 'v', 'e', ' ', 'f', 'i', 's', 'h', 'c', '.', 'c', 'o', 'm', '.', "'", ',', "'", 'I', ' ', 'l', 'o', 'v', 'e', ' ', 'y', 'o', 'u', ',', 'y', 'o', 'u', ' ', 'l', 'o', 'v', 'e', ' ', 'm', 'e', "'", ')')
代码二:
a = input('名字:')
print (a)
print(type(a))
输出:
名字:('i love you','you love me')
('i love you','you love me')
本帖最后由 jackz007 于 2022-10-28 19:40 编辑 def count(* params):
yingwen = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz'
shuzi = '0123456789'
kongge = ' '
zifu = '!~@#$%^&*()_{}[]?/|\<>,.`;:'
l = len(params)
print(l)
print(params)
for i in range(l):
s1=s2=s3=s4=0
for each in params[i]:
if each in yingwen:
s1 += 1
if each in shuzi:
s2 += 1
if each in kongge:
s3 += 1
if each in zifu:
s4 += 1
print('第%d个字符串共有:英文字母%d个,数字%d个,空格%d个,其他字符%d个.'%(i+1,s1,s2,s3,s4))
params = input('请传入字符串参数:')
eval('count' + params)
运行实况: D:\[00.Exerciese.2022]\Python>python x.py
请传入字符串参数:('I love fishc.com.','I love you,you love me')
2
('I love fishc.com.', 'I love you,you love me')
第1个字符串共有:英文字母13个,数字0个,空格2个,其他字符2个.
第2个字符串共有:英文字母17个,数字0个,空格4个,其他字符1个.
D:\[00.Exerciese.2022]\Python>
用这种方式调用一个函数,我也是 醉了
|
|