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

제목중간참조문제 4번2021-04-16 19:02
작성자
#영어단어 맞추기 함수
def getResult(status):
    if status.count('_') == 0:
        return 'You win'

    else : 
        return 'You lose'


def updateStatus(word,x,status):

    if x in word:
        cou = word.count(x)
        fin = 0
        for j in range(1,cou+1):
            fin = word.find(x,fin+1)
            new_status = status[:fin]+x+status[fin+1:]
        
    else:
        new_status = status

    print(new_status)
    return new_status


def startGame(word):
    status="_"*len(word)
    count = len(word)

    print(status)
    print(count,'chances.'

    for i in range(1,count+1):

        x = input("Enter the letter: ")
        updateStatus(word,x,status)

        print(count-i,'chances.')

        if word == status:
    
            return 'You win'
    print(getResult(status))
    return getResult(status)

    

startGame('HELLO')

이런식으로 코드를 짜면 x에 H를 넣었을 때 new_status=H____으로 바뀌지만 그뒤 다시
x에 E를 넣었을 경우 new_status=_E___로 나옵니다. status가 계속_____로 고정되어
있어서 그런거 같은데 status=new_status를 updateStatus함수 끝쪽에 넣으면 startG
ame함수로 넘어오면서 다시 _____로 바뀌고 statGame함수에 넣으면 정의되지않은 변수
라고 나오는데 어떻게 해야할까요?
댓글
이전step 9 나무 만들기2021-04-17
다음중간고사관련질문2021-04-16