我正在尝试制作一个程序,用户必须用符号代替字母才能得到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:
它没有用替换词重新打印所有编码的单词,而是简单地显示第一行。 我想知道是否有人知道我遗漏了什么或者我的代码有什么问题。 感谢您的帮助。你知道吗
如果我正确理解您的问题,您需要将
input
步骤移出for
循环。这就是你想要的:相关问题 更多 >
编程相关推荐