[英]How to replace blanks with guessed letters in Hangman game
Hey so i'm trying to create a simple hangman game in python. 嘿,所以我想用python创建一个简单的子手游戏。 So far I've got a very crude version of the program to work, doesn't do everything I want but it works.
到目前为止,我有一个非常粗略的程序版本可以工作,它不能完成我想要的一切,但是可以工作。 The Problem I'm having is trying to replace the blank dashes with whatever letter the user inputs.
我遇到的问题是尝试用用户输入的任何字母替换空白破折号。 I Honestly have no Idea of where to even begin to try and fix that so any help will be much appreciated.
老实说,我什至不知道从哪里开始尝试修复它,所以我们将不胜感激。
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()
Simplest way. 最简单的方法。
>>> dash = ["_", "_", "_", "_", "_", "_", "_"]
>>> dash[0] = 's'
>>> dash
['s', '_', '_', '_', '_', '_', '_']
>>> dash[2] = 'm'
>>> dash
['s', '_', 'm', '_', '_', '_', '_']
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.