tags:

views:

97

answers:

1

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[correct]
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)

+3  A: 

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."
gruszczy
If I had:{hints=dict(zip(WORDS, HINT))if guess=="hint": print "Here's a hint:", hints[correct]while (guess !=correct) and (guess != ""): print "Sorry, that's not it." 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)
Jam
Please, add this code to the question as an edit with code formatting, because right now it is impossible to say, what there is ;-)
gruszczy
Ok, I did that.
Jam