Guessing the correct character and line position

I am very new to coding and I am struggling with one of my first codes.

I want to create a word guessing game where the user realizes the character and position of several letters at a time. The step that I stuck can be summarized:

  • guess and selected word entered;
  • check if there are two letters in the selected word, the first 2 characters (+10 points for the correct letter); and
  • check if the two letters correspond to the correct location of the selected word (+50 points per correct letter).

I can not find a way to do this. This is what I still have. I want to continue the rest of the code myself, however it is incredibly difficult if I cannot go through the first step!

def compute_score(guess,position,word):
        """ Doc string """

        score = 0
        right_position_value = 100
        wrong_position_value = 20
        guess = input()
        position = pos for char in guess
        word_position = pos for char in word

        for char in word:
            if char in guess:
                    score += 10
            if position == word_position:
                    score += 50
            else:
                    score += 0

    return score

guess_1 = input('guess the first 2 letters corresponding to letters 1 and2 of the unkown word!: ')
print('Your guess and score were: ', guess, score)
+4
source share
1

, 1. , . , :

word = input('Choose your unknown word: ')
guess = input('guess the first 2 letters corresponding to letters 1 and2 of the unkown word!: ')

1!

2 3 , compute_score. , , :

def compute_score(guess,position,word):
    """ Doc string """

    score = 0
    right_position_value = 100
    wrong_position_value = 20
    guess = input()  <-- This will prompt the user for input a third time, and then
                         overwrite their initial guess with this one. 
    position = pos for char in guess  <-- Same problem here
    word_position = pos for char in word

, . , :

word_position = pos for char in word

, , for , . , for, :

for idx, char in enumerate(word):

(char), , (idx). :

>>> word = 'shape'
>>> for idx, char in enumerate(word):
...     print(idx)
...
0
1
2
3
4

, , 3 ( , position , )

2 . , . , . Python "" , :

for char in word:
    if char in guess[:2]:
            score += 10

.

, , , , , guess score compute_score. :

word = input('Choose your unknown word: ')
guess = input('guess the first 2 letters corresponding to letters 1 and2 of the unkown word!: ')

print('Your guess and score were: ', guess, calculate_score(guess, 0, word))

, 0 position, . , .

+1

Source: https://habr.com/ru/post/1683420/


All Articles