Я работаю над программой викторины и мне нужна помощь. Я пытаюсь заменить слова по одному, но Python не сохраняет ранее замененную строку. Вот небольшой пример того, что я имею в виду:
replacedQuiz=""
easyQuiz = """
You can change a string variable to an integer by typing (__1__)
in front of the variable. It also works vice versa, you can change an
integer
variable to a string by typing (__2__). This is important to remember before
you __3__ strings together, or else a TypeError will occur. While adding an
integer to a string, it is important to separate it using a __4__ (use the
symbol). \n"""
def replaceWord(replaced, quiz, numCount):
if numCount == 1:
replaced = quiz.replace("__1__", "int")
if numCount == 2:
replaced = replaced.replace("__2__", "str")
if numCount == 3:
replaced= replaced.replace("__3__", "concatenate")
if numCount == 4:
replaced= replaced.replace("__4__", ",")
print replaced
def easy():
QCount=1
print easyQuiz
while QCount < 5:
replaceWord(replacedQuiz, easyQuiz, QCount)
QCount += 1
print easy()
Я подумал, что, создав строку под названием replaceQuiz, она сохранит первую замену, а затем я смогу продолжить замену слов внутри теста и обновить его. Пожалуйста помоги! Я не знаю, где я иду не так