Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def main():
- words = ["apple","grape","brick","chair","flame","light","smile","crane","plant","clock","stone","river","bread","house","mouse","train","money","sound","green","laugh"]
- x = random.randint(1,len(words))
- ans = words[x]
- numGuesses=0
- solved=False
- while (numGuesses<5 and not solved):
- g = input('word? ').lower()
- res = checkGuess(g,ans)
- print(res)
- if not('*' in res or '+' in res):
- break
- numGuesses += 1
- if numGuesses == 5:
- print('You lose!')
- else:
- print('You win!')
- def checkGuess(guess,answer):
- ret=''
- i=0
- found=False
- for g in guess:
- if g == answer[i]:
- ret += g
- else:
- for a in answer:
- if g == a:
- found = True
- break
- if found:
- ret += '+'
- else:
- ret += '*'
- i += 1
- found = False
- return ret
- main()
Advertisement
Add Comment
Please, Sign In to add comment