재미로 만들어보는 로또번호 조회 프로그램


정말 로또되면 좋겠음


lotto.csv



lotto.py


from collections import *

from datetime import datetime

import csv

import os

import operator

import random

 

Lotto = namedtuple("Lotto", "items")

tlist = []

 

with open("lotto.csv") as csvfile:

    reader = csv.DictReader(csvfile) # csv 파일을 읽어서 dictionary 로 반환함

    for row in reader:

        lotto = Lotto(row)

        tlist.append(lotto)

 

 

def listFilter(strLambda):

    tmpList = list(filter(strLambda, tlist))

    hfnList = []

    for row in tmpList:

            hfnList.append(row.items["first_num"])

            hfnList.append(row.items["second_num"])

            hfnList.append(row.items["third_num"])

            hfnList.append(row.items["fourth_num"])

            hfnList.append(row.items["fifth_num"])

            hfnList.append(row.items["sixth_num"])

            hfnList.append(row.items["bonus_num"])

 

    d = {x:hfnList.count(x) for x in hfnList} #group by having count

    sorted_d = sorted(d.items(), key=operator.itemgetter(1), reverse = True) # sort #operator.itemgetter(0) = key, operator.itemgetter(1) = value

    return sorted_d

 

def HighFreqNum6():

    os.system('cls')

   

    tmpList = listFilter(lambda x: x == x)

   

    for i in range(6):

        print("{0} : {1}".format(tmpList[i][0], tmpList[i][1]))

 

    print("다른 메뉴를 사용하시려면 엔터를 눌러주세요")

    input()

 

def BetweenHighFreqNum6():

    os.system('cls')

    print("시작 기간을 적어주세요(yyyy-MM-dd) :")

    sdate = input()

    print(" 종료 기간을 적어주세요(yyyy-MM-dd) :")

    edate = input()

 

    tmpList = listFilter(lambda x: datetime.strptime(x.items["lucky_date"], '%Y-%m-%d') >= datetime.strptime(sdate, '%Y-%m-%d') \

                                and datetime.strptime(x.items["lucky_date"],'%Y-%m-%d') <= datetime.strptime(edate,'%Y-%m-%d'))

   

    os.system('cls')

    print("{0}일 부터 {1}일 까지의 가장 많이 나온 번호 6개 입니다.".format(sdate, edate))

 

    for i in range(6):

        print("{0} : {1}".format(tmpList[i][0], tmpList[i][1]))

 

    print("다른 메뉴를 사용하시려면 엔터를 눌러주세요")

    input()

 

def BetweenTurnHighFreqNum6():

    os.system('cls')

    print("시작 회차를 적어주세요:")

    sdate = input()

    print("종료 회차를 적어주세요:")

    edate = input()

 

    tmpList = listFilter(lambda x: int(x.items["lucky_time"]) >= int(sdate) and int(x.items["lucky_time"]) <= int(edate))

 

    os.system('cls')

    print("{0}회 부터 {1}회 까지의 가장 많이 나온 번호 6개 입니다.".format(sdate, edate))

 

    for i in range(6):

        print("{0} : {1}".format(tmpList[i][0], tmpList[i][1]))

 

    print("다른 메뉴를 사용하시려면 엔터를 눌러주세요")

    input()

 

def MakeNumber():

    balls = list(range(1, 46)) #1 ~ 45 까지의 리스트 생성

    random.shuffle(balls) # 리스트의 순서를 랜덤하게 섞는다

    return sorted(balls[:6]) # 0번부터 5번까지의 인자를 리턴한다

 

def MakeNumber6():

    os.system('cls')

    print("생성할 게임 횟수를 적어주세요:")

    gCnt = input()

 

    os.system('cls')

    for i in range(int(gCnt)):

        print("{0}회차 : {1}".format(i + 1 , MakeNumber()))

 

    print("다른 메뉴를 사용하시려면 엔터를 눌러주세요")

    input()

 

def main():

    while True:

        os.system('cls')

        print("1. 제일 많이 뽑힌 숫자 6개 확인")

        print("2. 일정 기간 중 제일 많이 뽑힌 숫자 6개 확인")

        print("3. 일정 회차 중 제일 많이 뽑힌 숫자 6개 확인")

        print("4. 완전 랜덤 번호 생성")

        print("")

        print("메뉴를 선택하세요.")

 

        select = input()

        select = select.strip()

        if select == "1" :

            HighFreqNum6()

        elif select == "2" :

            BetweenHighFreqNum6()

        elif select == "3" :

            BetweenTurnHighFreqNum6()

        elif select == "4" :

            MakeNumber6()

 

if __name__ == '__main__':

    main()

   

 

 

 





Posted by motolies
,