having an issue with a personal hangman project of mine, so im attempting to create a function that will display the current ungessed constonants, and ungessed vowels(first and second parameter) and the third parameter is the letter set player is guessing.
so for example:
>>> guessing_function('dfghjkls','ae','g')
'dfhjkls','ae'
the output is the letter guessed spliced from either the constoant list or vowel list. Sorry for bad english, thank you guys, below is the code i wrote trying to solve but it does not work, it simply returns the same thing you input, it doesnt actually remove the letter from the list.
def make_guessed(unguessed_cons,unguessed_vow,letter):
new_cons=""
for i in range(0,len(unguessed_cons)):
if unguessed_cons[i] == letter:
new_cons = unguessed_cons.replace (unguessed_cons,new_cons,[i])
return new_cons
I am not quite understand what do u mean, I guess follow is the implementation of guessing_function as u describe, is make_guessed the same as guessing_function?
def guessing_function(unguessed_cons,unguessed_vow,letter):
return unguessed_cons.replace(letter,''),unguessed_vow
Hint: You could make make_guessed
return (new_unguessed_cons,new_unguessed_vow)
then update the unguessed variables via:
unguessed_cons, unguessed_vow = make_guessed(unguessed_cons, unguessed_vow, letter)
At the moment your function only returns new_unguessed_cons
.
def make_guessed(unguessed_cons, unguessed_vows, letter):
for con in unguessed_cons:
if con == letter:
unguessed_cons = unguessed_cons.replace(letter, '')
break
for vow in unguessed_vows:
if vow == letter:
unguessed_vows = unguessed_vows.replace(letter, '')
break
return unguessed_cons, unguessed_vows
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.