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