jamyn
jamyn

Reputation: 1943

displaying numbers underneath a mask in python

background

Hey everybody, I'm attempting to code a basic letter game in python. In the game, the computer moderator picks a word out of a list of possible words. Each player (computer AI and human) is shown a series of blanks, one for each letter of the word. Each player then guesses a letter and a position, and are told one of the following:

  1. That letter belongs in that position (the best outcome)
  2. That letter is in the word, but not in that position
  3. That letter is not in any of the remaining blank spaces

When the word has been fully revealed, the player to guess the most letters correctly wins a point. The computer moderator picks another word and starts again. The first player to five points wins the game. In the basic game, both players share the same set of blanks they're filling in, so the players benefit from each other's work.

question

I'm using a mask to display the secret word as a series of dashes, in order to indicate to the player the number of letters in the word.

I want to display a numerical value underneath each dash, in order to make it easy for the player to select which character in the word he/she would like to guess.

So, in the case of a 4 letter word, the mask would display something like this:

- - - -
0 1 2 3

so far, my mask looks like this---

import random

with open('wordlist.txt') as wordList:
secretWord = random.choice(wordList.readlines()).strip()

mask = ' '.join(('_' for i in range(len(secretWord))))

Thanks!

Upvotes: 0

Views: 545

Answers (1)

Rushy Panchal
Rushy Panchal

Reputation: 17542

Why not make two strings?

mainMask = ' '.join(('_' for i in range(len(secretWord))))
numMask = ' '.join((str(i) for i in range(len(secretWord))))

Alternatively, you can put them into one:

mask = ' '.join(('_' for i in range(len(secretWord)))) + '\n' + ' '.join((str(i) for i in range(len(secretWord))))

Upvotes: 1

Related Questions