My goal:
The game Lingo has a hidden word, five characters long. The purpose of the game is to find this word, guessing, and in return get two kinds of clues: 1) characters that are completely correct in terms of identity and position, and 2) characters who are really present in the word, but who are placed incorrectly in the position. Write a program with which you can play Lingo. Use square brackets to indicate characters that are correct in the sense of 1), and regular parentheses to correctly label characters in the sense of 2)
Current code:
def lingo():
import random
words = ['pizza', 'motor', 'scary', 'motel', 'grill', 'steak', 'japan', 'prism', 'table']
word = random.choice(words)
print word
while True:
guess = raw_input("> ")
guess = list(guess.lower())
word = list(word)
for x in guess:
if x in word:
if x == word[word.index(x)]:
guess[guess.index(x)] = "[" + x + "]"
else:
guess[guess.index(x)] = "(" + x + ")"
print guess
lingo()
At the moment, if the words have a common letter, it puts the letter in square brackets, regardless of whether it has the same position or not.
Examples:
:
- : Table
- : Cater
- OUTPUT: C[a](t)(e)r
:
- : Japan
- My Guess: Ajpan ( a j, ).
- OUTPUT: [A][j][p][a][n] ( (a)(j)[p][a][n])