目前我的循环停止在用答案替换1。 如何循环它,使它用4个答案替换所有4个空格?你知道吗
easyQuiz = "There are ___1___ countries in the world. The countries with the biggest landmass is ___2___. The coldest continent in the world is ___3___. ___4___ is the capital of China"
blanks = ["___1___","___2___","___3___","___4___"]
easyAnswer = ["195","Russia","Antartica","Beijing"]
#asks users to choose difficulty level
question = raw_input("Shall we start? Easy, Medium, Hard?")
if question == "Easy" or question == "easy":
answerChoice = easyAnswer
answerChoice = answerList(question)
newprompt = []
newlist = []
index = 0
maxblanks = 3
for quizwords in difficulty(question).split():
if quizwords == "1" :
quizwords = quizwords.replace("1",answerChoice[index])
elif quizwords == "2" :
quizwords = quizwords.replace("2",answerChoice[index])
index = index + 1
newlist.append(quizwords)
joinedlist = " ".join(newlist)
可以使用字符串格式
可以将字符串格式与
regex
一起使用:输出:
你可以
zip
循环中的blanks
与相应的easyAnswer
和replace
循环。你知道吗或
zip
到dict
并将re.sub
与回调一起使用:相关问题 更多 >
编程相关推荐