Hi there, I'm learning python by myself and I've just come to big stop with my first project for a Hang/man. I need some help. Thank you.
Here's my code:
It's mostly that I can't get the function newdisp to replace the underscore with a letter that's been guessed (and replace all same letters).
For the missing I will do it in the main.
Here's my code:
Code:
def get_secret():
initial = raw_input('enter string: ')
word = initial.lower()
print '\n'*60
return str(word)
def do_turn(display, misses):
print 'Word so far: ', display
print 'Missed :', misses
flag = False
while flag == False:
letter = str(raw_input('Pick a letter to guess: '))
if len(letter)==1:
flag = True
else:
print 'Cmon man, enter ONE letter'
return letter
def new_display(secret, display, letter):
temp = ''
for i in range(len(secret)):
if secret[i] in letter:
temp = temp[:i] + secret[i] + temp[i+1:]
for letter in temp:
print (letter), display
return temp
secret = get_secret()
display = len(list(secret))*'_ '
misses = 0
correct = ''
tries = 0
#print 'This is the word: ', display
print list(secret) #this actually converts the secret to a list
for i in range(8):
letter = do_turn(display, misses)
guess = new_display(secret, display, letter)
while False:
if letter in guess:
print 'bravo'
For the missing I will do it in the main.
Comment