question is : Write a function that accepts three parameters, a string and two integers. The string represents a word in a guessing game. The two integer represent positions to keep the letters as a starting point. The remaining letters should be replaced by the * symbol. The function should return the resulting string.
The doctests below should make this clear:
def hangman_start(strng, pos1, pos2):
"""
>>> hangman_start("banana", 0, 5)
'b****a'
>>> hangman_start("passionfruit", 0, 7)
'p******f****'
>>> hangman_start("cherry", 3, 4)
'***rr*'
>>> hangman_start("peach", 2, 10)
'**a**'
>>> hangman_start("banana", -1, -1)
'******'
"""
if __name__=="__main__":
import doctest
doctest.testmod(verbose=True)
I tried do this as below:
def hangman_start(strng, pos1, pos2):
count=0
result=""
while count<len(strng):
if strng[count]==strng[pos1] or strng[count] == strng[pos2]:
result += strng[count]
else:
result += "*"
count+=1
return result
but it does not work properly.
such as: hangman_start("banana", 0, 5)
i got ba*a*a
.
Any kind guy can help me with this?