How do I get a position from a word and also match the letters plural?

405
May 03, 2017, at 5:27 PM

So right now I am working on a game and am very confused on this particular definition of my code. Yes, honestly it is a project that I have to do but I did everything but one Definition. Basically I am making a hangman game in python. I have the input and output in the terminal (with the stick figure in a separate window using graphics). I am having trouble with this: I have the random word, for ex, "microwave". I need to match the letter to the position and count how many words have the letter 'a' in that same position. I am able to match the letter and position but not after I unconvered one. So when I search for v, or an other letter, I want to search for words that have a and v, in that same position. Here is what I have. If you'd like me to post my full code, I can. similar = 'a' position = 6 list = a dictionary of words wrong_letters = a list of letters that were guessed but arent in the word microwave and shouldnt be in any other matched words. (for ex. if passed t and s, the next word shouldnt have a t or s but should have an a and v at position 6 and 7)

def similarity(similar_letter, position,list,wrong_letters):
how_many_matched_words = 0
for word in list:
    count = -1
    for char in word:
        count += 1
        for pos in range(len(word) - 1):
            if char.upper() == similar_letter:
                if pos == position:
                    print(word)
                    how_many_matched_words += 1
    print(how_many_matched_words)

Here is the teachers definition if this helps: In the text window, print the number of words in the word list that match the pattern of the currently revealed word and the list of incorrect guesses. For example, if the revealed word is _ E _ _ and the list of incorrect guesses is T and S, then you would count the words that have 4 letters, with exactly one E (in the second position) and no T's or S's. It is possible to do this using only what we've learned in class, but you are welcome to further explore Python string methods if you like.

Rent Charter Buses Company
READ ALSO
Except an error in Python from a loaded C library

Except an error in Python from a loaded C library

I have this piece of code which loads a library, but then it diesI've surrounded it with the try/except pass, but it still dies

395
With Python using SimpleOSC or OSC directly, can you control the rate of the data returned to the server?

With Python using SimpleOSC or OSC directly, can you control the rate of the data returned to the server?

I have a simple example where I have an OSC enabled device sending data to an animation applicationThe evaluation of the functions starts to lag behind the interactive OSC device

375
Selecting every options from a drop-down box using selenium python

Selecting every options from a drop-down box using selenium python

I am trying to extract some data from a websiteHowever, the site has a hierarchical structure

389