我的任务是编写一个脚本,将第二个数字写入s
并将其位置写入标准输出
输入示例:
afg 456 gg 677
示例输出:
677 12
除了print
部分之外,我的代码都是正确的-它打印的是第一个数字及其位置,而不是第二个:
s = input()
i = 0
while i < len(s) and (s[i] < "0" or "9" < s[i]):
i = i + 1
if i < len(s):
j = i
while j < len(s) and "0" <= s[j] and s[j] <= "9":
j = j + 1
print(s[i:j], len(s[0:i]))
我想这是一个有限制的家庭作业吧?因此,这里有一个愚蠢而有教育意义的例子。只需增加计数器
i
并再次运行相同的循环:不是为了现实生活
相关问题 更多 >
编程相关推荐