TEAMLAB-Lecture / python-101-for-data-science-by-pknu

1 stars 14 forks source link

baseball_game main 함수에 관한 질문 #38

Open 54162476 opened 2 years ago

54162476 commented 2 years ago
def main():
    print("Play Baseball")
    random_number = str(get_not_duplicated_three_digit_number())
    print("Random Number is : ", random_number)
    user_input = input("Input guess number : ")
    while True :
        if is_validated_number(user_input):
            strike , ball = get_strikes_or_ball(user_input , random_number)
            if strike == 3 :
                while True :
                    strike , ball = get_strikes_or_ball(user_input , random_number)
                    print("Strikes : ", strike, "Balls : ", ball)
                    one_more_input = input("You win, one more(Y/N)?")
                    if is_yes(one_more_input):
                        random_number = str(get_not_duplicated_three_digit_number())
                        print("Random Number is : ", random_number)
                        user_input = input("Input guess number : ")
                        break
                    elif is_no(one_more_input):
                        print("Thank you for using this program")
                        print("End of the Game")
                        break
                    else :
                        print("Wrong Input, Input again")                      

            else :
                strike , ball = get_strikes_or_ball(user_input , random_number)
                print("Strikes : ", strike, "Balls : ", ball)
                user_input = input("Input guess number : ")
                continue
        else :
            print("Wrong Input, Input again") 
            user_input = input("Input guess number : ")

교수님 다 되는데 n이나 no를 입력했을 때 게임이 끝나는 걸 해결을 못하겠습니다.

blissray commented 2 years ago

위릐 while 문이 break 한번으로 깨지지 않네요. 이럴경우에는 위 while을 빠져나오기 위해 위의 while의 조건을 지정해주고 is_no 일 경우 그 조건을 만족한다고 하면 되요

blissray commented 2 years ago

예를 들면 flag 기법을 사용할 수 있습니다.

54162476 commented 2 years ago
def main():
    print("Play Baseball")
    random_number = str(get_not_duplicated_three_digit_number())
    print("Random Number is : ", random_number)
    user_input = input("Input guess number : ")
    flag = True
    while flag :
        if is_validated_number(user_input):
            strike , ball = get_strikes_or_ball(user_input , random_number)
            if strike == 3 :
                strike , ball = get_strikes_or_ball(user_input , random_number)
                print("Strikes : ", strike, "Balls : ", ball)
                while True:
                    one_more_input = input("You win, one more(Y/N)?")
                    if is_yes(one_more_input):
                        random_number = str(get_not_duplicated_three_digit_number())
                        print("Random Number is : ", random_number)
                        user_input = input("Input guess number : ")
                        break

                    elif is_no(one_more_input):
                        flag = False
                        break
                    else :
                        print("Wrong Input, Input again")    
                        continue                  

            else :
                strike , ball = get_strikes_or_ball(user_input , random_number)
                print("Strikes : ", strike, "Balls : ", ball)
                user_input = input("Input guess number : ")
                continue
        else :
            print("Wrong Input, Input again") 
            user_input = input("Input guess number : ")    

    print("Thank you for using this program")
    print("End of the Game")

이렇게 해서 다 완료했는데 제출이 되지 않습니다.