0
我正在嘗試構建一個簡單的遊戲,但我在更新列表時遇到問題並重新打印它的任何想法?更新列表並重新打印它?
我從一個txt文件中提取一些細節並將它們放入一個列表中。我列出了這個清單,這個工作。
我使用.replace進行更新,但是當我重新打印列表時,它只打印列表中的最後一個項目。這已被正確更新。我怎樣才能得到它,所以它再次打印已更新的整個列表?
任何想法???
這裏是我的代碼:
print("Can you solve the puzzle? \nBelow are some words in code form can you crack the code and figue out\nthe words?\n")
words = open ("words.txt", "r")
lines_words = words.readlines()
for line_words in lines_words:
print (line_words)
words.close()
print("\nHere are some clues to help you!\n")
clues = open ("clues.txt", "r")
print (clues.read())
clues.close()
###
print ("\nThis is what we have so far....")
# define the function
def replace_all(text, dic):
for i, j in dic.items():
text = text.replace(i, j)
return text
# dictionary with key:values.
reps = {'#':'A', '*':'M', '%':'N'}
txt = replace_all(line_words, reps)
print (txt)
謝謝你這幫了很多!我可以繼續構建我的遊戲並使用TKinter開發界面。 – user3078517