#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목중간참조 4 질문2021-04-18 15:30
작성자

def getResult(status):

    if '_' in status:

        a= "You lose"

        return a

        

    else: 

        a= "You win"

        return a


def updateStatus(word, x, status):

    if status == word:

        getResult(status)

    else:

        if word.count(x) > 0 :

            if word.count(x) == 1:

                status = status[:word.find(x)] + x + status[word.find(x)+1:]

                new_status = status

                return new_status

            elif word.count(x) > 1:

                for i in range(0,word.rfind(x)+1):                       

                    if word[i] == x:

                        status = status[:i] + x + status[i+1:]

                    else:

                        continue

                new_status = status    

                return new_status

        else: 

            new_status = status

            return new_status


   def startGame(word):

    status = "_" * (len(word))

    print(status)

    for i in range(len(word),0,-1):

        print(i, "chances.", end=' ')

        a= input("Enter a letter: ")

        updateStatus(word, a, status)

    return getResult(status)


word = 'HIPPOPOTAMUS'    

result = startGame(word) 

print(result)     



를 실행하면 

____________
12 chances. Enter a letter: H
11 chances. Enter a letter: P

이런 식으로 쭉 나오다가 모든 글자를 입력해도 결국 you loose가 나옵니다.. 그리고 updatestatus에서 new_status를 반환하라고 해놨는데도 반환값도 나오지 않구요 ㅠㅠㅠ무엇이 원인인지 아무리 고민해도 모르겠습니다 ㅠ 
댓글
이전module 질문 있습니다2021-04-18
다음 step 12 마지막 질문 있습니다2021-04-18