如果连续正确回答x次,则显示一条消息

用户名

我正在为自己的任务开发游戏,并且卡在某个部件上,如果用户连续5次正确回答,那么我需要显示一条消息,例如“太棒了,您是这个大师”。像这样的东西:

if correct_guesses == 5 and incorrect_guesses == 0 :
    print("""CONGRATULATIONS! You have figured it  all out Great work mate!!""")

我已经设置了可记录正确和错误猜测答案的字符串

现在,如果正确的猜测等于5,我的代码将执行代码并打印,但是如果我得到一个错误的猜测,它将不会显示,有什么帮助吗?

玩偶

每当答案错误时,您都需要重置计数器。结构如下所示:

game_is_running = True # we run the game as long as this is True
counter = 0
while game_is_running:
  was_correct = ask_question() # ask_question() is a function that prints the question and check if it was answered correctly. It correct, return True otherwise return False
  if was_correct: # if the answer was correct, we increase the counter
    counter += 1
  else: # if it was false, we reset it to 0 (we need 5 IN A ROW, right?)
    counter = 0
  if counter == 5: # if we had 5 correct answers in a row, we print and then the game is finished
    print("CONGRATULATIONS! You have figured it all out! Great work mate!!")
    game_is_running = False

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Keycloak-如果用户被阻止,则显示一条消息

如果用户未登录,则显示一条消息

如何连续20个月每月显示一条新消息

f:ajax验证一次仅显示一条消息

如何一次在asp.net的验证摘要中仅显示一条消息

如果没有退回WooCommerce短代码的产品,则显示一条消息

即使语句显示一条矛盾的消息,如果它似乎仍然失败

如果特定文件夹为空,则在屏幕上显示一条消息

如果数据库中不存在用户,则显示一条消息

如果把手列表为空,则显示一条消息

JSX如果字典数组中的值相同,则显示一条消息

如果尝试捕获C#中未捕获到异常,则显示另一条消息

Android ListView,如果arrayAdapter的arrayList为空,则显示一条消息

XSL如果元素的计数为0,则向用户显示一条消息

每当我输入正确的密码时,都会显示一条错误消息

仅显示一条通用消息,而不是每个输入一条消息

显示消息数组中的最后一条消息

ServiceBusTrigger:会话一次接收一条消息

一次只拉出一条消息

附加最后一条消息一次

如何创建for循环并延迟以每X秒显示一条消息?

我想更改状态消息,如果成功则显示成功,然后返回我的第一条消息

我只想显示一条消息到Internet Explorer(10 -11)并每天显示一次

[React]: UseRef to scrollIntoView 最后一条消息如果需要

如果用户已经预订了同一家酒店,则向用户显示一条消息

在Spring MVC验证中,一次每个字段只能显示一条错误消息吗?

如何在foreach循环中显示一条消息?

如何使用AngularJS每秒显示一条消息?

只为我的输入数组显示一条验证消息