Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import random
  2. with open("G:\pycharm projects\dictionary.txt",'r') as dict:
  3. dictionary=dict.read().split()
  4. def hangman():
  5.  
  6. word=random.choice(dictionary)
  7. length,i=len(word),6
  8. ans=["_"]*length
  9. print(" ".join(ans))
  10. chances=[]
  11. while i>0:
  12. print("\nYou have ", i, " chances.",end=" " )
  13. while True:
  14. a=str(input(" Enter a letter "))
  15. a=a.upper()
  16. chances.append(a)
  17. print("\nWritten letters "," ".join(chances))
  18. if a in word:
  19. for count in range(len(ans)):
  20. if word[count]==a:
  21. ans[count]=a
  22. count+=1
  23. print(" ".join(ans))
  24. else:
  25. print("wrong")
  26. break
  27. if "_" in ans:
  28.  
  29. i -= 1
  30. else:
  31. print("\nYou have won and helped the man from hanging")
  32. break
  33. if "_" in ans:
  34. print("\nYou Lost and the correct answer is ",word)
  35.  
  36.  
  37. hangman()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement