ssoni

wordle.py

Feb 3rd, 2026
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import random
  2.  
  3. def main():
  4.     words = ["apple","grape","brick","chair","flame","light","smile","crane","plant","clock","stone","river","bread","house","mouse","train","money","sound","green","laugh"]
  5.     x = random.randint(1,len(words))
  6.     ans = words[x]
  7.    
  8.     numGuesses=0
  9.     solved=False
  10.     while (numGuesses<5 and not solved):
  11.         g = input('word? ').lower()
  12.         res = checkGuess(g,ans)
  13.         print(res)
  14.         if not('*' in res or '+' in res):
  15.             break
  16.         numGuesses += 1
  17.        
  18.     if numGuesses == 5:
  19.         print('You lose!')
  20.     else:
  21.         print('You win!')
  22.  
  23.  
  24. def checkGuess(guess,answer):
  25.     ret=''
  26.     i=0
  27.     found=False
  28.     for g in guess:
  29.         if g == answer[i]:
  30.             ret += g
  31.         else:
  32.             for a in answer:
  33.                 if g == a:
  34.                     found = True
  35.                     break
  36.             if found:
  37.                 ret += '+'
  38.             else:
  39.                 ret += '*'
  40.         i += 1
  41.         found = False
  42.     return ret                
  43.  
  44. main()
Advertisement
Add Comment
Please, Sign In to add comment