Python
[Python] 로또 당첨번호 (별찍기 예제)
현기
2022. 7. 26. 13:44
로또 당첨번호를 별찍기를 활용해 출력한다.
import random
win_number = random.sample(range(1,46),7)
def first(arr):
print("====1등 당첨번호====")
print(arr[0:6])
def second(arr):
print("====2등 당첨번호====")
for i in range(0,len(arr)-1):
for j in range(0, len(arr)):
if(i==j):
print('*', end=' ')
else:
print(arr[j], end=' ')
print()
def third(arr):
print("====3등 당첨번호====")
for i in range(0,len(arr)-1):
for j in range(0, len(arr)-1):
if(i==j):
print('*', end=' ')
else:
print(arr[j], end=' ')
print()
def fourth(arr):
print("====4등 당첨번호====")
for i in range(0,len(arr)-1):
for j in range(i+1, len(arr)-1):
for k in range(0,len(arr)-1):
if k==i:
print('*', end=' ')
elif k==j:
print('*', end=' ')
else:
print(arr[k], end=' ')
print()
def fifth(arr):
print("====5등 당첨번호====")
for i in range(0,len(arr)-1):
for j in range(i+1, len(arr)-1):
for k in range(j+1,len(arr)-1):
for m in range(0,len(arr)-1):
if m==i:
print('*', end=' ')
elif m == j:
print('*', end=' ')
elif m == k:
print('*', end=' ')
else:
print(arr[m], end=' ')
print()
first(win_number)
second(win_number)
third(win_number)
fourth(win_number)
fifth(win_number)