0
ちょっと、私は単純なハングマンゲームをPythonで作成しようとしています。私のコードのいくつかが役に立たないように見える場合は、ちょうど私と一緒に裸にしてください。これまでのところ、私は仕事のためのプログラムの非常に粗末なバージョンを持っている、私が望むすべてをしないで動作します。私が抱えている問題は、ユーザーが入力した文字と空白のダッシュを置き換えようとしています。私は正直なところ、どのような助けが大いに評価されるかを試して修正しようとする考えをどこにも持っていません。Python Hangman Game:空白を推測された文字と置き換える方法
word = "samsung"
dash = ["_", "_", "_", "_", "_", "_", "_"]
guessedLetters = []
def functionOne():
print("The Secret word is: ", dash)
wrongLettersGuessed = " "
guessLeft = 5
while guessLeft <= 5:
guess = input("What is your guess: ")
if guess in word:
print("Correct")
guessedLetters.append(guess)
print(guessedLetters)
if len(guessedLetters) == len(word):
print("YOU GOT IT !!!")
print("The word was: samsung")
break
else:
wrongLettersGuessed = guess + wrongLettersGuessed
guessLeft = guessLeft - 1
print("Incorrect")
print("Letters guessed", wrongLettersGuessed)
print(guessLeft)
if guessLeft <= 0:
x = guessLeft + 1
print("Sorry you lost the game, the word was samsung")
playAgain = input("Would you like to play again (yes or no):")
if playAgain == "no":
break
functionOne()
ダッシュは文字列リストなので、空白を新しい文字列で置き換えるにはstring.replace(oldstring、new string)を使用できます。 –