Python三重嵌套循环不完全迭代

时间:2014-08-18 07:53:51

标签: python

基本上,当我运行此代码时会发生的是" print block [j]"我的程序部分运行,但我之后的所有测试代码,即打印块[k]和打印"测试代码"没达到。我过去半小时一直在盯着这个程序而且无法弄清楚为什么程序可以超越第二个嵌套循环而不是第三个嵌套循环。

def SwapII(str): 
  new_str = ""
  for letter in str:
    if letter.isupper():
      new_str = new_str + letter.lower()
    else:
      new_str = new_str + letter.upper()

  new_list = new_str.split(' ')


  for i in new_list:
    block = i.split()

    for j in range(len(block)):
        print block[j]
        for k in range(j+1, len(block)):
            print block[k]
            if block[j].isdigit() and block[k].isdigit():
                lala = block[j]
                block[j] = block[k]
                block[k] = lala
                print "testing code"



    i = ''.join(block)


  return ' '.join(new_list)



# keep this function call here  
# to see how to enter arguments in Python scroll down
print SwapII(raw_input()) 

0 个答案:

没有答案