Python/연습장

중복검사 왜 안되는지 알아내기

joo_coding 2025. 3. 6. 09:21

# 이거 중복검사 부분 왜 안되는지 찾아보자

list_ = []
switch = True

while switch:
    user_input = input("1~45 사이, 중복x, 한글x \n숫자를 입력하세요: ")

    if user_input.isnumeric(): #숫자인지 아닌지 판별
        user_input = int(user_input)  # 숫자가 맞으면 int화 시키고

        if 1 <= user_input <= 45:

            for num in list_:
                if user_input == num:
                    print("중복된 숫자입니다. 다시 골라주세요.")
                    continue
                else:
                    list_.append(user_input)  # 리스트에 추가

            print(f"고른 숫자:{list_}")

            if len(list_) == 6:
                switch = False
                break

        else:
            print("1~45 사이의 숫자만 입력 해주세요.")
            print("")
    else:
        print("잘못된 입"
              "력입니다. 숫자만 입력 해주세요.")