File tree Expand file tree Collapse file tree 1 file changed +98
-0
lines changed
Expand file tree Collapse file tree 1 file changed +98
-0
lines changed Original file line number Diff line number Diff line change 1+ import random
2+ import time
3+ import pickle
4+ import os .path
5+
6+
7+ def print_program_name ():
8+ print ()
9+ print ("*" * 30 )
10+ print (" 선물 추첨 프로그램 Ver 0.1" )
11+ print ("*" * 30 )
12+
13+
14+ def save_result (result ):
15+ with open ("gift_lottery_result.txt" , "a+" , encoding = "utf8" ) as f :
16+ f .write (result + "\n " )
17+
18+
19+ def clear_result ():
20+ with open ("gift_lottery_result.txt" , "w+" , encoding = "utf8" ) as f :
21+ f .write ("" )
22+
23+
24+ def save_names (names ):
25+ with open ("gift_lottery.pickle" , "wb" ) as f :
26+ pickle .dump (names , f )
27+
28+
29+ print_program_name ()
30+
31+ if os .path .exists ("gift_lottery.pickle" ):
32+ with open ("gift_lottery.pickle" , "rb" ) as f :
33+ arr = pickle .load (f )
34+ else :
35+ arr = []
36+
37+ lottery_name = []
38+
39+ while True :
40+ menu = input ("\n 메뉴 선택(1.추첨 2.결과 조회 3.결과 삭제 4.이름 초기화 5.이름 출력 6.이름추가 9.종료): " )
41+ if menu == "1" :
42+ gift = input ("선물 이름을 입력하세요: " )
43+ inwon = int (input ("추첨 인원을 입력하세요: " ))
44+ lottery_cnt = inwon #추첨 인원
45+
46+ for i in range (lottery_cnt ):
47+ random .shuffle (arr )
48+ random .shuffle (arr )
49+ random .shuffle (arr )
50+ for i in range (0 ,100 ,2 ):
51+ print (f"\r { i } " , end = '' )
52+ time .sleep (0.05 )
53+
54+ s = arr .pop ()
55+ lottery_name .append ([gift ,s ])
56+ save_result ("{} - {}" .format (gift , s ))
57+ print (f"\r 추첨 --> { s } " )
58+ time .sleep (2 )
59+
60+ print ()
61+ print ("*" * 20 )
62+ print (" 선물 당첨자 명단" )
63+ print ("*" * 20 )
64+ no = 1
65+ for i in lottery_name :
66+ print (no , ":" , i )
67+ no += 1
68+
69+ elif menu == "2" :
70+ print ()
71+ print ("*" * 20 )
72+ print (" 선물 당첨자 명단" )
73+ print ("*" * 20 )
74+ no = 1
75+ for i in lottery_name :
76+ print (no , ":" , i )
77+ no += 1
78+
79+ elif menu == "3" :
80+ lottery_name = []
81+ clear_result ()
82+
83+ elif menu == "4" :
84+ arr = []
85+
86+ elif menu == "5" :
87+ print (arr )
88+
89+ elif menu == "6" :
90+ tmp = input ("추가할 이름을 입력하세요(,으로 구분): " )
91+ names = tmp .split ("," )
92+ arr .extend (names )
93+ print (names ,"을 추가하였습니다." )
94+
95+ elif menu == "9" :
96+ save_names (arr )
97+ print ("프로그램이 종료되었습니다!" )
98+ break
You can’t perform that action at this time.
0 commit comments