2014-02-20 63 views
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-我想创建一个由''组成的空白字,其长度等于单词的长度,'正确'的字母在正确的位置被替换为''。我对如何做到这一点感到困惑。 我知道使用列表替换函数,但是如何在第一个地方创建空白字?

你没有给我答案,如果它是我应该找出或复杂。请指出我正确的方向。

谢谢! :)

回答

0
graphics=['''------------ 
      |   |  ''',''' 
------------ 
|   | ''',''' 

------------ 
|   |   
|   O''',''' 
------------ 
|   | 
|   O 
|  /|''',''' 
------------ 
|   | 
|   O 
|  /| 
|   | ''',''' 
------------ 
|   | 
|   O 
|  /| 
|   | 
|  /| 
| 
|   '''] 

graphics中的每个字符串都以换行符开头。

字符串中的换行符加上隐含的换行给你的文字和图形之间的空行。

格式化字符串,使在同一行'''-----开始删除多余的换行符