Advertisement
robjones90

Wordle

Jun 1st, 2022
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import random
  2.  
  3. def word_list():
  4.     with open('5_letter_words.txt') as f:
  5.         words_list = f.read().splitlines() #removes /n
  6.     f.close()
  7.     return words_list
  8.  
  9. def random_word(words_list):
  10.     return random.choice(words_list)
  11.  
  12. def is_real_word(guess, words_list):
  13.     return guess in words_list
  14.  
  15. def check_guess(guess, words_list):
  16.     choice = random_word(words_list)
  17.     print("Debug: random choice = ", choice)
  18.     print("Guess: ->", guess)
  19.  
  20.     for number in range(0,5):
  21.         position = choice.find(guess[number])
  22.         if choice[number] in guess and position == number: # letter exists in random choice
  23.             if position == number: # if in correct place, write x
  24.                 print('x')
  25.             else: # if in the wrong place
  26.                 pass #case doesn't exist
  27.         if choice[number] != guess[number]: #if guess isn't the same
  28.             if guess[number] not in choice:
  29.                 #if letter doesn't exist in randomly chosen word write
  30.                 print("_")
  31.             if guess[number] in choice and position != number:
  32.                 #if letter exists but isn't the correct position
  33.                 print("o")
  34.  
  35. def next_guess():
  36.     pass
  37.  
  38. def play():
  39.     pass
  40.  
  41. #print(random_word(word_list()))
  42.  
  43. #print(is_real_word('words', word_list()))
  44.  
  45. #is_real_word(guess, print(word_list()))'''
  46. check_guess('mnesc', word_list())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement