在设计智力竞赛游戏时需要一些帮助。我用Python编写了以下内容:一个字符串和一个列表。在
quiz_string = '''there are two types of loops in programming. The blank1 loop and the blank2 loop'''
answer_list = ['for', 'while']
用户将被提示如下:什么应该在空白1?在
如果用户回答“for”,则questing_string变量中的“blank1”将替换为answer_list变量中的“for”。对blank2重复此过程。在
如果有任何关于代码的帮助,我们将不胜感激。在
string.replace()
可能会有帮助。在例如:
您可以根据需要修改验证。在
可以使用带适当变量的格式字符串:
当用户输入正确的答案时,您将用用户的输入替换}。在
guesses
中的元素,并再次进行相同的print
调用。然后它将用guesses
中的新值替换{相关问题 更多 >
编程相关推荐