小编Hir*_*ora的帖子

按某个步骤移动字符串的所有字母

  • 输入:['baNaNa', 7] #字符串和步长
  • 所需的输出:'utGtGt'# 字符串的每个字符按步长向后移动
import ast  
in_string = input()  
lis = ast.literal_eval(in_string)  
st = lis[0]  
step = lis[1]  
alphabets = 'abcdefghijklmnopqrstuvwxyz'  
password = ''  
for letter in st:  
    if letter in alphabets:  
        index_val = alphabets.index(letter) - (step)  
        password += alphabets[index_val]  

print(password)
Run Code Online (Sandbox Code Playgroud)

我得到的输出是“utgtgt”。我想要'utGtGt'。对此的帮助将不胜感激。

python string indexing loops python-3.x

0
推荐指数
1
解决办法
396
查看次数

标签 统计

indexing ×1

loops ×1

python ×1

python-3.x ×1

string ×1