python - 如何祝贺玩家使用提示而不以不同方式使用它
问题描述
我想知道如何告诉计算机使用提示为玩家打印不同的输入,以及为不使用提示的人打印不同的输入来祝贺他们
import random
words = dict(
python = "type of snake",
honda = "type of car",
spanish = "type of language",)
word = list(words)
var = random.choice(word)
score = 0
chance = 5
x = list(var)
random.shuffle(x)
jumble = "".join(x)
print("the jumble word is :", jumble,)
while True:
guess = input(" this is my guess :")
if guess == "hint":
print(words[var])
if guess == var:
print("well done you only used ", score,"to guessed it ")
break
else:
print("try again")
score +=1
if score == chance:
print("better luck next time")
break
解决方案
如果添加一个布尔值,比如hintUsed
,来跟踪用户是否使用了提示:
hintUsed = False
while True:
guess = input(" this is my guess :")
if guess == "hint":
hintUsed = True # change hintUsed to True !!
print(words[var])
然后,祝贺:
if guess == var:
if hintUsed:
#print a message
else:
#print another message
break
推荐阅读
- c# - 用户控件中的滑块,如何将其值绑定到父窗口中的缩放数据网格
- excel - 间接函数到 Averageif
- email - Imap 电子邮件 ID 回到 0
- c++ - C++ 习惯用法:如何将右值作为右值传递?
- javascript - Ember Data 返回内部模型数组而不是实际数据
- java - 基于signedBy执行Java安全策略
- android - 通过 FirebaseAuth UI 登录 Facebook 失败
- php - 如何使用 PHP 语言对数据库 Oracle 执行多个查询
- sql - AWS Redshift:出现“and not true”子句时删除挂起
- reactjs - 使用 ThreeJS 和 Dat.Gui 更新网格的纹理