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])
嗨!这是我几乎完成的刽子手游戏。我只有两个问题。
1-图形和印刷线之间有一个线条空间。 例如 - &gt;
这封信不在单词中。
| |
如何消除这种差距?
2-我想创建一个由''组成的空白单词,其长度等于单词的长度,其中'正确'字母在正确的位置用''代替。我对如何做到这一点很困惑。 我知道要使用列表替换功能,但我如何首先创建一个空白字?
如果这是我应该弄清楚或复杂的事情,你不必给我答案。请指出我正确的方向。
谢谢! :)
答案 0 :(得分:0)
graphics=['''------------
| | ''','''
------------
| | ''','''
------------
| |
| O''','''
------------
| |
| O
| / |''','''
------------
| |
| O
| / |
| | ''','''
------------
| |
| O
| / |
| |
| / |
|
| ''']
graphics
中的每个字符串都以换行符开头。
字符串中的换行符加上隐式换行符会在文本和图形之间显示空白行。
重新格式化字符串,使-----
与'''
在同一行开始,以删除额外的换行符