def lol(plaintext,row,col,group):
val=''
for ch in range(0,1000000,group):
if ch>=row*col: #reset value of ch to the next col
break
val=val+''
ch = ch - (row+1)*group +1
continue
if ch>(row+2)*group: #to prevent exceedimg
break
val=val+(plaintext[ch])
return val #return encrypted message
print(lol("ILIKEDRINKINGLEMONADEWITHICEIN", 6,5,5))
答案 0 :(得分:0)
第一次运行for循环时,ch为0,如果if语句有条件,则不满足。
val=val+(plaintext[ch])
return val #return encrypted message
val设置后,您的函数在设置一个字符后立即返回。尝试取消您的退货声明:
def lol(plaintext, row, col, group):
val = ''
for ch in range(0, 1000000, group):
if ch >= row * col: #reset value of ch to the next col
break
val = val + ''
ch = ch - (row + 1) * group + 1
continue
if ch > (row + 2) * group: #to prevent exceedimg
break
val = val + (plaintext[ch])
return val # this now returns after the for loop finishes.