IndexError:RLE python 中的字符串索引超出范围
如果我输入A9输出AAAAAAAAA但我输入A10程序将出现错误索引超出范围。当我输入A10或以上时,如何修复程序,程序可以正常工作。 这是我的代码
Char = input ("Input Char : ")
Total = len(Char)
Decompress =""
for i in range (0, Total,2):
Loop = int(Char[i+1])
for j in range (0, Loop):
Decompress = Decompress + Char [i]
print("Output : ",Decompress)
if i input A9 output AAAAAAAAA but i input A10 program will be error index out of range. how to fix the program when im input A10 or above the program is workly.
This my code
Char = input ("Input Char : ")
Total = len(Char)
Decompress =""
for i in range (0, Total,2):
Loop = int(Char[i+1])
for j in range (0, Loop):
Decompress = Decompress + Char [i]
print("Output : ",Decompress)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里不需要一个循环(或两个循环!)。
只需将字符串相乘:
输出:
更通用的输入
假设您想要处理重复的字符/数字对,这很容易使用正则表达式来实现:
示例:
You don't need a loop (or two loops!) here.
Simply multiply the string:
output:
more generic input
assuming you want to handle repeated pairs of char(s)/digits, this is quite easy to achieve with a regex:
example: