import random

# 변수 설정
lottery_price = 30000  # 복권 가격
lottery_count = 1000  # 복권 구매 갯수 (예시)
simulation_count = 100  # 반복할 시뮬레이션 횟수 (예시)

# 당첨 번호와 구매한 번호 비교 후 등수 판별 함수
def check_prize(winning_numbers, ticket_numbers):
    # 일치하는 번호의 개수를 셈
    matched = len(set(winning_numbers) & set(ticket_numbers))
    
    # 등수에 따라 반환할 상금
    if matched == 6:
        return "1등", 20000000
    elif matched == 5:
        return "2등", 500000
    elif matched == 4:
        return "3등", 150000
    elif matched == 3:
        return "4등", 50000
    elif matched == 2:
        return "5등", 20000
    elif matched == 1:
        return "6등", 10000
    else:
        return "7등", 0

# 시뮬레이션 함수
def lottery_simulation():
    total_spent = lottery_price * lottery_count  # 총 지출 금액
    total_winnings_all_simulations = 0  # 모든 시뮬레이션에서의 상금 총합
    
    # 시뮬레이션 반복
    for _ in range(simulation_count):
        total_winnings_in_simulation = 0  # 각 시뮬레이션에서의 상금
        
        for _ in range(lottery_count):
            # 당첨 번호 랜덤 생성 (1~80 중 6개)
            winning_numbers = random.sample(range(1, 81), 6)
            # 복권 번호 랜덤 생성 (1~80 중 24개)
            ticket_numbers = random.sample(range(1, 81), 24)
            
            # 당첨 여부 확인
            prize, amount = check_prize(winning_numbers, ticket_numbers)
            total_winnings_in_simulation += amount
        
        total_winnings_all_simulations += total_winnings_in_simulation  # 시뮬레이션별 상금 합산
    
    # 시뮬레이션 평균 상금
    average_winnings = total_winnings_all_simulations / simulation_count
    
    return total_spent, average_winnings

# 시뮬레이션 실행
spent, average_winnings = lottery_simulation()

# 결과 출력
print()
print(f"시뮬레이션 반복 횟수: {simulation_count:,} 번")
print()
print(f"복권 구매 갯수: {lottery_count:,} 개")
print()
print(f"복권 구매 금액: {spent:,} 원")
print(f"평균 상금 금액: {average_winnings:,.0f} 원")
print(f"평균 수익 금액: {average_winnings - spent:,.0f} 원")
print()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: