这段代码应该接受一个字符串输入并输出另一个字符串,它只是输入字符串的修改版本 . 我不能让它工作 .
它应该输出一个字符串,其中每个字母是输入字符串的下一个字母 . 但是在运行代码时,它只输出相同的输入字符串而不是修改后的字符串 .
def str_changer(string):
string_list = list(string)
alphabets = 'abcdefghijklmnopqrstuvwxyz'
positions = []
for letter in string_list:
positions.append(alphabets.index(letter))
for each in positions:
each = each + 1
for each in string_list:
string_list[string_list.index(each)] =
alphabets[positions[string_list.index(each)]]
another = ''.join(string_list)
return another
lmao = raw_input('Enter somin\'')
print str_changer(lmao)
2 回答
你可以在 1-line 中完成:
Demo :
这应该适合你 . 您应该使用
%
来计算z
.重点是你不需要明确地 Build 一个职位列表 .