开发者

Giving 'hints' problem

开发者 https://www.devze.com 2022-12-19 11:25 出处:网络
I have a simple word jumble game. I made the jumble already, but now I want to add a \'hint\' system. I don\'t know how to have 1 item from tuples show up. I have 2 tuples, and I want to pull from the

I have a simple word jumble game. I made the jumble already, but now I want to add a 'hint' system. I don't know how to have 1 item from tuples show up. I have 2 tuples, and I want to pull from the 2nd tuple based on the what the first tuple is. I have a WORD=("x", "y", "z") and HINT=("x", "y", "z"). When the user enters "hint", I want the program to return the corresponding value from HINT. I tried:

for h in HINT:
    if guess=="hint":
        print h

Obviously, this doesn't work, and just prints all of the HINT values.

If I had:

hints=dict(zip(WORDS, HINT))
if guess=="hint":
    print "Here's a hint:", hints[corr开发者_Go百科ect]
while (guess !=correct) and (guess != ""):
    print "Sorry, that's not the answer."
    guess=raw_input("Your guess: ")
    guess=guess.lower()
    if guess==correct:
        print "That's it! You guessed it!\n"
print "Thanks for playing."

would there be any way for me to make it NOT print "Sorry, that's not it."? (also, 'correct' here is the word)


Create a dictionary:

  hints = dict(zip(WORD, HINT))

and then:

  if guess=='hint':
    print hints[current_word]

Simple if is not enough?

if guess != 'hint':
  print "Sorry, that's not the answer."
0

精彩评论

暂无评论...
验证码 换一张
取 消