feat: 구현 완료
This commit is contained in:
parent
ed6924e1e6
commit
67e37ff31e
1 changed files with 42 additions and 0 deletions
42
draw.py
Normal file
42
draw.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
import time
|
||||
|
||||
def dev_urandom_index(lists: list):
|
||||
with open('/dev/urandom', 'rb') as urandom:
|
||||
random_bytes = urandom.read(2)
|
||||
random_number = int.from_bytes(random_bytes, 'big')
|
||||
random_index = random_number % len(lists)
|
||||
return random_index
|
||||
|
||||
def draw_from_list(lists: list, draw_count: int):
|
||||
draweds = []
|
||||
for _ in range(draw_count):
|
||||
random_index = dev_urandom_index(lists)
|
||||
drawed = lists.pop(random_index)
|
||||
draweds.append(drawed)
|
||||
return draweds
|
||||
|
||||
def color_text(text: str, color_code: str):
|
||||
start = f"\033[{color_code}m"
|
||||
reset = "\033[0m"
|
||||
return f"{start}{text}{reset}"
|
||||
|
||||
def view(num: int, drawed: str):
|
||||
print(f"\n{num}번째 당첨자를 선정합니다...")
|
||||
time.sleep(1)
|
||||
print(".", end="", flush=True)
|
||||
time.sleep(1)
|
||||
print(".", end="", flush=True)
|
||||
time.sleep(1)
|
||||
print(".\n")
|
||||
print(f"축하합니다! {num}번째 당첨자는 {color_text(drawed, 36)}님 입니다!")
|
||||
time.sleep(1.5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
draw_count = input("당첨자 수를 입력하세요: ")
|
||||
lists = input("참가자 리스트를 공백으로 구분하여 입력하세요: ").split()
|
||||
draweds = draw_from_list(lists, int(draw_count))
|
||||
for num, drawed in enumerate(draweds):
|
||||
view(num + 1, drawed)
|
||||
|
||||
print("\n최종 당첨자: " + color_text(f"{' '.join(draweds)}", 36))
|
Loading…
Reference in a new issue