print('Welcome to Hangman! Guess the mystery word with less than 6 mistakes!')
while True:
words=['table','chair','pencil','stapler','pen','computer',
'printer','cable','books','shelf']
alphabet=['a','b','c','d','e','f','g,','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x','y','z']
number=input('Please enter an integer number (0<=number<10)
to choose the word in the list:')
if number=='':
print('Empty input!')
continue
elif number in alphabet:
print('Input must be an integer!')
continue
number=int(number)
if number<0 or number>9:
print('Index is out of range!')
continue
elif 0<=number<10:
break
words2=[]
words2.extend(words[number])
print('The length of the word is: ',len(words2))
i=0
j=0
while j<6 or i!=len(words2):
即使在6个错误(错误= j和word = i中的字母)
之后游戏仍在继续 letter=input('Please enter the letter you guess: ')
for alphabet in letter:
if alphabet in words2:
print('The letter is in the word.')
i=i+1
if i==len(words2):
print('You have found the mystery word. You win!')
print('Goodbye!')
break
之前的休息无效。是因为它只会导致FOR循环而不是循环吗?
else:
continue
elif alphabet not in words2:
if letter not in alphabet:
print('You need to input a single alphabetic character!')
elif letter not in words2:
j=j+1
print('The letter is not in the word.')
您好!这是我正在写的刽子手游戏。我面临两个问题
谢谢
我查找了类似的问题,但没有一个具有特定的解决方案,我也尽力编辑这个问题。
答案 0 :(得分:0)
我不是百分百肯定,但我认为你的测试是错误的
while j<6 or i!=len(words2):
应该是
while j<6 and i!=len(words2):