Python/연습장

안끝나는 자판기

joo_coding 2025. 2. 24. 19:12
while True: #break 걸기 전까지 영원히 안끝남
    user_money2 = input("돈을 넣어주세요.: ")  # input함수로 반환하면 문자형으로 반환되기때문에
    user_money2 = int(user_money2)  # 숫자형으로 바꿔주는 과정 필요
    user_select2 = input("음료를 골라주세요.: ")

    if user_money2 >= 900 and user_select2 == "코카콜라":
        print("코카콜라")
        user_money2 = user_money2 - 900
    elif user_money2 < 900 and user_select2 == "코카콜라":
        print("돈이 부족합니다.")
    elif user_money2 >= 800 and user_select2 == "펩시콜라":
        print("펩시콜라")
        user_money2 = user_money2 - 800
    elif user_money2 < 800 and user_select2 == "펩시콜라":
        print("돈이 부족합니다.")
    elif user_money2 >= 700 and user_select2 == "포카리":
        print("포카리")
        user_money2 = user_money2 - 700
    elif user_money2 < 700 and user_select2 == "포카리":
        print("돈이 부족합니다.")
    elif user_money2 >= 500 and user_select2 == "물":
        print("물")
        user_money2 = user_money2 - 500
    elif user_money2 < 500 and user_select2 == "물":
        print("돈이 부족합니다.")

    else:  # 돈x메뉴x=메뉴x
        user_select2 != "코카콜라", "펩시콜라", "포카리", "물"
        # user_money2 < 900 and user_select2 != "코카콜라"
        # user_money2 < 800 and user_select2 != "펩시콜라"
        # user_money2 < 700 and user_select2 != "포카리"
        # user_money2 < 500 and user_select2 != "물"
        print("해당 메뉴가 존재하지 않습니다.")
    print(user_money2)