如何在替换后重新打印代码-python 3.2

如何在替换后重新打印代码-python 3.2,python,decode,substitution,Python,Decode,Substitution,我正在尝试制作一个程序,在这个程序中,用户必须用符号替换字母,以获得10个解码单词。我已经设法使替代工作,但当它更新只有一行显示,而不是所有的。 以下是我尝试将符号替换为字母的代码: subs2=[] for word in words_list: tempword = (word) tempword = tempword.replace('#','A') tempword = tempword.replace('*', 'M') tempword = tempw

我正在尝试制作一个程序,在这个程序中,用户必须用符号替换字母,以获得10个解码单词。我已经设法使替代工作,但当它更新只有一行显示,而不是所有的。 以下是我尝试将符号替换为字母的代码:

subs2=[]
for word in words_list:
    tempword = (word)
    tempword = tempword.replace('#','A')
    tempword = tempword.replace('*', 'M')
    tempword = tempword.replace('%', 'N')

    addpair1=input("Enter a symbol you would like to replace:")
    addpair2=input("What letter would you like to replace it with:")
    tempword=tempword.replace(addpair1,addpair2)
    print(tempword)
    subs2.append(tempword)
print(subs2[0])
print(subs2[1])
print(subs2[2])
print(subs2[3])
print(subs2[4])
print(subs2[5])
print(subs2[6])
print(subs2[7])
print(subs2[8])
print(subs2[9])
但是,当我尝试替换符号时,会出现以下情况:

A+/084&"
A3MANA+
8N203:
,1$&
!-MN
.A7&33&
AMA71N
&-&641'2
A))85
9&330M
Enter a symbol you would like to replace:3
What letter would you like to replace it with:h
A+/084&"
Enter a symbol you would like to replace:
它只显示第一行,而不是用替换重新打印所有的编码字。 我想知道是否有人知道我遗漏了什么或者我的代码有什么问题。
感谢您的帮助

如果我正确理解了您的问题,您需要将
输入从
for
循环中移出。这就是你想要的吗:

words_list=["hi", "my","name","is"]

subs2=[]
addpair1=input("Enter a symbol you would like to replace:")
addpair2=input("What letter would you like to replace it with:")

for word in words_list:
    tempword = (word)
    tempword = tempword.replace('#','A')
    tempword = tempword.replace('*', 'M')
    tempword = tempword.replace('%', 'N')
    tempword=tempword.replace(addpair1,addpair2)
    print(tempword)
    subs2.append(tempword)
print subs2

#Enter a symbol you would like to replace:"i"
#What letter would you like to replace it with:"j"
#hj
#my
#name
#js
#['hj', 'my', 'name', 'js']

您的代码与输出不匹配。此外,循环中还有一个
print
语句,因此它当然只打印一行。总的来说,您的代码没有什么意义:您正在遍历一个单词列表,要求用户选择一个要替换的字符(我可能会添加,甚至不先显示单词),然后将每个单词添加到列表中。最后,当
单词列表
用尽时,打印前十个单词。那到底是为了什么?