Play the Hangman game!
from math import * def play_hangman(): p=print clr="\n"*50 ttl=" ** Hangman **\n\n\n" nttl=clr+ttl inpt=lambda q:input("Press 'HOME' to exit\n\n"+q) p(nttl+"\n"*2) w=inpt("Enter a word: ") if len(w)==0:return hm() fnd=[False]*len(w) err=[] p(clr) while True: t=nttl+"Word: " for i in range(len(w)): t+=w[i]if fnd[i]else"_" t+="\n"*3+"Errors:\n"+", ".join(err)+"\n" p(t) if all(fnd): p("You won!\n") break elif len(err)>=10: p("Lost, it was '"+w+"'\n") break i=inpt("Input: ") if len(i)!=1:pass elif i in w: for j in range(len(w)): if w[j]==i:fnd[j]=True elif i not in err: err.append(i) y=input("Play again? (Press 'y')") if y=="y":return play_hangman() p("Bye!") def hmpg(): try: play_hangman() except: print("Bye") hmpg()