首页 > 解决方案 > 如何祝贺玩家使用提示而不以不同方式使用它

问题描述

我想知道如何告诉计算机使用提示为玩家打印不同的输入,以及为不使用提示的人打印不同的输入来祝贺他们

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 

标签: pythonpython-3.x

解决方案


如果添加一个布尔值,比如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

推荐阅读