2017-02-06 84 views
-1

我在做一個hang子手程序,我希望它能夠包含短語;但是,當我輸入要猜測的短語時,輸出只會破折號。例如,當我輸入「你好嗎」(輸入被猜測)時,輸出是「-----------」。我想要的是「--- --- ---」,因爲它讓玩家更容易知道它是一個短語。我已經嘗試了一個'for'循環和'if'語句,現在可用,並希望得到一些幫助。謝謝! *目前我正在嘗試更換。另外,如果這措辭不好,讓我知道,我會嘗試重寫它。如何用空格替換「 - 」?

right = "" 
guess="" 
attempts = 6 
tries = 0 
space = " " 

print("Hangman: guess letters until you can guess the word or phrase.") 
print("In this game you get six tries.") 

right_str = str(input("\nEnter your word: ")) 
right_str = right_str.lower() 

#displays the proper amount of unknown spaces 
right = right * len(right_str) 

if space in right_str: 
    right_str.find(space, i) 
    print(i) 
+0

這是代碼的一部分。我可以發佈其餘的,如果這會讓它更容易 – Veyronvenom1200

+0

什麼是'我'? 「find」是純粹的afaik。它不會改變任何東西。 – Carcigenicate

+0

我以爲我是索引 – Veyronvenom1200

回答

3

你可以試試這個:

guess="" 
attempts = 6 
tries = 0 
space = " " 

print("Hangman: guess letters until you can guess the word or phrase.") 
print("In this game you get six tries.") 

right_str = str(input("\nEnter your word: ")) 
right_str = right_str.lower() 

output = "" 
for c in right_str: 
    if c != " ": 
     output += "-" 
    else: 
     output += " " 
print output