简体   繁体   English

在Hangman游戏中如何用猜中的字母替换空格

[英]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.

相关问题 Python中的刽子手游戏:如何用猜测的字母替换空格 - Hangman game in Python: how to replace blanks with guessed letters 刽子手游戏没有打印出猜测的正确字母 - Hangman Game not Printing Out Correct Letters Guessed 如果秘密词中的所有字母都在guessed_letters列表中,如何在hangman中结束游戏 - How to end game in hangman if ALL letters in the secret word are in guessed_letters list 用Python编程以显示在show子手游戏中猜到的字母不起作用 - Program in Python to show letters guessed in a hangman game not working 在Hangman游戏中存储猜词 - Storing the guessed word in Hangman game Discord.py 刽子手游戏 - 机器人识别猜测字母位置的问题 - Discord.py hangman game - problem with bot recognizing positions of guessed letters 用猜测的字母代替破折号 / Hangman / Python - Putting guessed letters instead of dashes / Hangman / Python 如何知道用户猜到了刽子手中的哪些字母,以及如何根据它们在秘密单词中的索引将它们存储在最终列表中 - How to know which letters in hangman the user guessed and how to store them in the final list accordingly to their index in the secret word hang子手游戏取代字母 - hangman game substituting letters 如何在刽子手中用选定的字母替换下划线 - How to replace the underscores with chosen letters in hangman
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM