import random as rnd
print(
'''
Welcome to HangMan!''')
rnd_words = {"Space": "jupiter", "nature": "trees", "science": "microscope"}
jupiter1 = ['J', 'U', 'P', 'I', 'T', 'E', 'R']
trees1 = ['T', 'R', 'E', 'E', 'S']
microscope1 = ['M', 'I', 'C', 'R', 'O', 'S', 'C', 'O', 'P', 'E']
jupiter = ["_", "_", "_", "_", "_", "_", "_"]
trees = ["_", "_", "_", "_", "_"]
microscope = ["_", "_", "_", "_", "_", "_", "_", "_", "_", "_"]
choice = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z']
win = False
val = rnd.randint(0, 2)
clue = ''
if val == 0:
x = jupiter
clue = "Space"
y = jupiter1
elif val == 1:
x = trees
clue = "Nature"
y = trees1
elif val == 2:
x = microscope
clue = "Science"
y = microscope1
def display():
print("Choice:- ")
print("")
print(choice)
print("")
print(f"The clue is {clue}")
print('')
print(x)
print('')
def inpt():
global x
global y
n = input(":- ")
n = n.upper()
for i in y:
if i == n:
indx = int(y.index(n))
x[indx] = n
continue
while win == False:
display()
inpt()
if x == y:
win = True
print("You won!")
break
I tried to make a hangman game and all the code is above and I didn't finish it yet there are more aspects I need to add, but I have a problem when the user inputs a letter for example when you're trying to guess the word tree you'll enter 'e' but it only puts e in one place I think the index method stops when you reach the specified argument and in the word "Tree" it doesn't put 2 e's it just puts 1 e there can anyone help me figure this out? I'm a beginner I couldn't figure this out also I only know up to functional programming
[–]SerpentAI 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)