0
graphics=['''------------
| | ''','''
------------
| | ''','''
------------
| |
| O''','''
------------
| |
| O
| /|''','''
------------
| |
| O
| /|
| | ''','''
------------
| |
| O
| /|
| |
| /|
|
| ''']
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))
print('')
i=0
j=0
x=0
while j<6 and i!=len(words2):
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
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.')
print(graphics[j])
嗨!這是我幾乎完成的hang子手遊戲。我只有2個問題。劊子手顯卡空白Word創建和空間除去
1-有圖形和印刷線之間的線間距。 對於示例 - >
這封信是不是在這個詞。
| |
如何刪除這個差距?
2-我想創建一個由''組成的空白字,其長度等於單詞的長度,'正確'的字母在正確的位置被替換爲''。我對如何做到這一點感到困惑。 我知道使用列表替換函數,但是如何在第一個地方創建空白字?
你沒有給我答案,如果它是我應該找出或複雜。請指出我正確的方向。
謝謝! :)