I am working on a python version of the game Lingo. Here are the rules:

"Suppose the secret word is bones. Suppose you guess the word books. The computer will mark your guess as [o](o)k[s], where , [o], and [s] are letters that are in the correct position in the secret word. The clue (o) states that the letter o is in the secret word, but not in the correct position. The clue k represents that the letter k is not in the secret word. You must make sure that the user types in a valid five letter word as a guess. If the guess is not a five letter word, the user loses their turn. The user has five
chances to guess the secret word."

the output should resemble something similar to the following:

SECRET WORD : b _ _ _ _
*** ROUND # 1 ( Guesses left : 5) ***
Guess ? books
Clue : [ b ][ o ]( o ) k [ s]
*** ROUND # 2 ( Guesses left : 4) ***
Guess ? boils
Clue : [ b ][ o ] il [ s ]
*** ROUND # 3 ( Guesses left : 3) ***
Guess ? boars
Clue : [ b ][ o ] ar [ s ]
*** ROUND # 4 ( Guesses left : 2) ***
Guess ? bores
Clue : [ b ][ o ] r [ e ][ s]
*** ROUND # 5 ( Guesses left : 1) ***
Guess ? bones
Clue : [ b ][ o ][ n ][ e ][ s ]
Congratulations ! BONES was the secret word .

I am able to pick a random word from a .txt file, and I am able to gather user input for the guess. My trouble lies in comparing the guess to the actual word (the example above was more to see the mechanics of the guessing system, I can figure out the print options myself). Any ideas on a function to compare the guess and actual word?

In Python all strings are also arrays, therefore you can easily manipulate them as such, I'll give some code as it is probably easier to comprehend than a wall of text :)

word = "bones"

for i in range(len(word)):
    c = word[i]
    print c



Now to find if a letter is in the right place you could ask:

letter == word[i]

And to see if a letter is in a string:

letter in word

I'll leave the implementation to you, but that should get you started.

- Joe

This article has been dead for over six months. Start a new discussion instead.