words = ['cow', 'horse', 'deer', 'elephant', 'lion', 'tiger', 'baboon', 'donkey', 'fox', 'giraffe']print('welcome to Hangman! Guess the mystery word with less than 6 mistakes!')#guess number=ii=input('Please enter an integer number (0<=number<10) to choose the word in the list:')#defdef f(k): if k==1: return('------------\n| |') if k==2: return('------------\n| |\n| O') if k==3: return('------------\n| |\n| O\n| / |') if k==4: return('------------\n| |\n| O\n| / |\n| |') if k==5: return('------------\n| |\n| O\n| / |\n| |\n| / |') if k==6: k=k+6 return('------------\n| |\n| O\n| / |\n| |\n| / |\n| \n| \nToo many incorrect guesses. You lost!')
def word(i): i=int(i) if i==0 or i==8: return('___') elif i==1 or i==5 or i==6 or i==7: return('_____') elif i==2 or i==4: return('____') elif i==3: return('________') else: return('_______')#checkingtry: x=int(i) except Exception as err: print('Input must be an integer!') i=input('Please enter an integer number (0<=number<10) to choose the word in the list:')if i==' ': print("Input must no be empty.") i=input('Please enter an integer number (0<=number<10) to choose the word in the list:')elif ((int(i)<0) or (int(i)>=10)): print('Index is out of range!') i=input('Please enter an integer number (0<=number<10) to choose the word in the list:')else: a=words[int(i)]L=0k=0#game b=len(a)print('the length of the letter is %s' %b)g=word(i)q=list(g)#mathch=m postion=palist=list(a)b=len(a)c1=' 'while k<6: c=input('Please enter the letter you guess:') if c1==c: c=input('Please enter the DIFFERENT letter you guess:') p=0 m=0 while p<b: if c!=alist[p]: p=p+1 else: q[p]=c m=m+1 p=p+1 if m!=0: L=m+L print('the letters is in the word') print('letters has matched so far:', ''.join(q)) c1=c if L==b: print('you win') break else: k=k+1 print('The letter is not in the word.') print(f(k)) c1=c