如何用空格替换“ - ”?

时间:2017-02-06 03:21:54

标签: python

我正在制作一个刽子手程序,我希望它能够包含短语;但是,当我输入要猜到的短语时,输出只会破折号。例如,当我输入“你好吗”时(输入被猜到),输出是“-----------”。我想要的是“--- --- ---”,因为它让玩家更容易知道它是一个短语。我已经尝试了'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)

1 个答案:

答案 0 :(得分: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