|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 foxdai 于 2020-4-8 18:23 编辑
#回文联函数
def Laihui():
'回文联即用回文形式写成的对联,即可顺读,也可倒读。例如:上海自来水来自海上'
sentence = input("请输入一句话:")
if len(sentence) % 2 == 0 or len(sentence) <3:
LaiHui = False
else:
length = len(sentence)
Laihui = False
for i in range(int((length-1)/2)):
if sentence[i] == sentence[length-i-1]:
LaiHui = True
else:
LaiHui = False
break
if LaiHui:
print('是回文联')
else:
print('不是回文联')
#计数,含子函数count1(x)
def count(*params):
cellcounts = len(params)
for i in range(cellcounts):
print('第',i+1,' 个字符串共有:',end='')
count1(params[i])
#计数的子函数
def count1(x):
#判断为整数,则转为字符
if type(x) == int:
x = str(x)
#计数
length = len(x)
alphas = nums = spaces = others = 0
for i in range(length):
if x[i].isalpha():
alphas += 1
else:
if x[i].isnumeric():
nums += 1
else:
if x[i].isspace():
spaces += 1
else:
others += 1
print('英文字母 ','%2d' % alphas,' 个,数字 ','%2d' % nums,' 个,空格 ',\
'%2d' % spaces,'个,其他字符 ','%2d' % others,'个。')
|
|