displaying numbers underneath a mask in python -
background
hey everybody, i'm attempting code basic letter game in python. in game, computer moderator picks word out of list of possible words. each player (computer ai , human) shown series of blanks, 1 each letter of word. each player guesses letter , position, , told 1 of following:
- that letter belongs in position (the best outcome)
- that letter in word, not in position
- that letter not in of remaining blank spaces
when word has been revealed, player guess letters correctly wins point. computer moderator picks word , starts again. first player 5 points wins game. in basic game, both players share same set of blanks they're filling in, players benefit each other's work.
question
i'm using mask display secret word series of dashes, in order indicate player number of letters in word.
i want display numerical value underneath each dash, in order make easy player select character in word he/she guess.
so, in case of 4 letter word, mask display this:
- - - - 0 1 2 3
so far, mask looks this---
import random open('wordlist.txt') wordlist: secretword = random.choice(wordlist.readlines()).strip() mask = ' '.join(('_' in range(len(secretword))))
thanks!
why not make 2 strings?
mainmask = ' '.join(('_' in range(len(secretword)))) nummask = ' '.join((str(i) in range(len(secretword))))
alternatively, can put them one:
mask = ' '.join(('_' in range(len(secretword)))) + '\n' + ' '.join((str(i) in range(len(secretword))))
Comments
Post a Comment