马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
s = input("输入:")
m = []
n = []
for i in s:
if i.isdecimal():
m.append(i)
else:
n.append(i)
lenm = len(m)
lenn = len(n)
if abs(lenm - lenn) > 1:
print("输出:字符串中数字和字母的数量不满足重新格式化的条件")
else:
if lenm > lenn:
shorter = lenn
longer = lenm
else:
shorter = lenm
longer = lenn
result = []
for each in range(len(shorter)):
result.append(longer[each])
result.append(shorter[each])
if len(longer) > len(shorter):
result.append(longer[-1])
print("".join(result))
这串代码哪里出问题了啊?
总是报错:如下所示
应该怎么修改啊!!!
object of type 'int' has no len()
s = input("输入:")
m = []
n = []
for i in s:
if i.isdecimal():
m.append(i)
else:
n.append(i)
lenm = len(m)
lenn = len(n)
if abs(lenm - lenn) > 1:
print("输出:字符串中数字和字母的数量不满足重新格式化的条件")
else:
if lenm > lenn:
shorter = n # 改了这里
longer = m # 改了这里
else:
shorter = m # 改了这里
longer = n # 改了这里
result = []
for each in range(len(shorter)):
result.append(longer[each])
result.append(shorter[each])
if len(longer) > len(shorter):
result.append(longer[-1])
print("".join(result))
|