How do I add a specific letter to a variable and then make it a string

Noob

I am trying to make a hangman game and I am not fully sure on how to add a specific letter to a variable. For example, adding a letter that someone chose through the pythons' input prompt to a variable. Here is the code I am working on:

import random
import time

word_list = ['that', 'poop', 'situation', 'coding', 'python', 'turtle', 'random', 'passive', 'neutral', 'factor', 'time']
word_chosen = random.choice(word_list)

your_name = input("What is your name?")
time.sleep(1)
print("Hello " + your_name + ", lets play some hangman!, The amount of letters in the word is below!")
guesses = 7

time.sleep(1)
hidden_word = ""
for i in word_chosen:
  hidden_word += "-"
while True:
  n = 1
  time.sleep(1) 
  print("Your word is: " + hidden_word)
  print("___________")
  print("|")
  print("|")
  print("|")
  print("|")
  print("|")
  print("|")
  print("|")
 


  characters = (word_chosen)
  time.sleep(1)
  letters_correct = ""
  characters_guessed = input("Type in the letters you think are in this word!")
  for i in characters:
    hidden_word == characters_guessed
    
  if characters_guessed == characters:
    print(hidden_word + characters)
  else:
    int(guesses) - int(n)
    print("Nope, sorry.")
Ritesh Khanna

I have modified your code @Noob and made it work. Instead of using strings I have made lists of chosen_word ,characters and characters_guessed .In this code you can even enter more than one word at a time. It automatically fillsup the repitive words and will tell the user if he or she has won or lost the game.

import random
import time

word_list = ['that', 'poop', 'situation', 'coding', 'python', 'turtle', 'random', 'passive', 'neutral', 'factor', 'time']
word_chosen = random.choice(word_list)
your_name = input("What is your name?")
time.sleep(1)
print("Hello " + your_name + ", lets play some hangman!, The amount of letters in the word is below!")

guesses = 7

time.sleep(1)
hidden_word = [" - " for i in range(len(word_chosen))]
while guesses>0:
    time.sleep(1) 
    print("Your word is: "+ "".join(hidden_word))
    print("___________")
    for i in range(7):
        print("|")


    characters = list(word_chosen)
    time.sleep(1)
    letters_correct = ""
    characters_guessed = input("Type in the letters you think are in this word!").split()

    for j in characters_guessed:
        if j not in characters:
            guesses-=1
            print(f"Wrong guess, {j} is not in the word")
        else:
            for i in characters:
                if i==j:
                    find_position=0
                    for k in range(characters.count(i)):
                        hidden_word[characters.index(i,find_position)]=j
                        find_position+=characters.index(i,find_position)+1
        
    if " - " not in hidden_word:
        print("Congratulations, you have won the game.The word was {chosen_word}")
        break

    elif guesses==0:
        print("Opps!! out of guesses. You have lost the game.")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I make inheritable class variable?

From Dev

how to make two or more combinations of specific letter?

From Dev

How do I find words starting with a specific letter?

From Dev

How do I add a character at a specific position in a string?

From Dev

In TI-BASIC, how do I add a variable in the middle of a String?

From Dev

How do I make a single letter in a string uppercase

From Dev

How do I find words starting with a specific letter and delete that row?

From Dev

How do I check if a Java String contains at least one capital letter, lowercase letter, and number?

From Dev

How do I slice a string in python based on the text, not the letter number?

From Dev

How do I make a string of ","?

From Dev

How do I make sure that a string value is not passed into an int variable?

From Dev

How do I create a method that capitalizes the first letter of a string in java?

From Dev

How do I capitalized any two letter word in a string in addition to the first letter of any word?

From Dev

How do I grab each letter of a string in android?

From Dev

How do I make inheritable class variable?

From Dev

How to search for specific letter in a word, then add that word with that letter to a list?

From Dev

How Do I make Date a Variable?

From Dev

How do I make this work? I need my variable options to be more specific

From Dev

How do I identify in a string that a letter has a number beside?

From Dev

How do I pass a specific string to my partial depending on the value of another variable also being passed to it?

From Dev

How can I add these characters to every line that includes a specific letter in a specific column? (notepad++)

From Dev

How do I find a combination of a letter a number in a VBA string?

From Dev

How do i make random letter from a string?

From Dev

How to color specific letter in a string variable (js,angularjs)

From Dev

How do i invert every odd letter in a string?

From Dev

how do i remove a letter from string

From Dev

How do I make a S or K letter in for loop java

From Dev

How do I make an array add up?

From Dev

How do i add color into a nested letter

Related Related

  1. 1

    How do I make inheritable class variable?

  2. 2

    how to make two or more combinations of specific letter?

  3. 3

    How do I find words starting with a specific letter?

  4. 4

    How do I add a character at a specific position in a string?

  5. 5

    In TI-BASIC, how do I add a variable in the middle of a String?

  6. 6

    How do I make a single letter in a string uppercase

  7. 7

    How do I find words starting with a specific letter and delete that row?

  8. 8

    How do I check if a Java String contains at least one capital letter, lowercase letter, and number?

  9. 9

    How do I slice a string in python based on the text, not the letter number?

  10. 10

    How do I make a string of ","?

  11. 11

    How do I make sure that a string value is not passed into an int variable?

  12. 12

    How do I create a method that capitalizes the first letter of a string in java?

  13. 13

    How do I capitalized any two letter word in a string in addition to the first letter of any word?

  14. 14

    How do I grab each letter of a string in android?

  15. 15

    How do I make inheritable class variable?

  16. 16

    How to search for specific letter in a word, then add that word with that letter to a list?

  17. 17

    How Do I make Date a Variable?

  18. 18

    How do I make this work? I need my variable options to be more specific

  19. 19

    How do I identify in a string that a letter has a number beside?

  20. 20

    How do I pass a specific string to my partial depending on the value of another variable also being passed to it?

  21. 21

    How can I add these characters to every line that includes a specific letter in a specific column? (notepad++)

  22. 22

    How do I find a combination of a letter a number in a VBA string?

  23. 23

    How do i make random letter from a string?

  24. 24

    How to color specific letter in a string variable (js,angularjs)

  25. 25

    How do i invert every odd letter in a string?

  26. 26

    how do i remove a letter from string

  27. 27

    How do I make a S or K letter in for loop java

  28. 28

    How do I make an array add up?

  29. 29

    How do i add color into a nested letter

HotTag

Archive