Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def word_list():
- with open('5_letter_words.txt') as f:
- words_list = f.read().splitlines() #removes /n
- f.close()
- return words_list
- def random_word(words_list):
- return random.choice(words_list)
- def is_real_word(guess, words_list):
- return guess in words_list
- def check_guess(guess, words_list):
- choice = random_word(words_list)
- print("Debug: random choice = ", choice)
- print("Guess: ->", guess)
- for number in range(0,5):
- position = choice.find(guess[number])
- if choice[number] in guess and position == number: # letter exists in random choice
- if position == number: # if in correct place, write x
- print('x')
- else: # if in the wrong place
- pass #case doesn't exist
- if choice[number] != guess[number]: #if guess isn't the same
- if guess[number] not in choice:
- #if letter doesn't exist in randomly chosen word write
- print("_")
- if guess[number] in choice and position != number:
- #if letter exists but isn't the correct position
- print("o")
- def next_guess():
- pass
- def play():
- pass
- #print(random_word(word_list()))
- #print(is_real_word('words', word_list()))
- #is_real_word(guess, print(word_list()))'''
- check_guess('mnesc', word_list())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement