-
파이썬 random으로 만든 로또 시뮬레이터코딩 2021. 5. 16. 00:14
import random i = 1 Lotto = [] while i < 46: Lotto += [i] i += 1 random.shuffle(Lotto) WinningNum = Lotto[0:6] WinningNum.sort() Bonus = Lotto[6] print('당첨번호 : {0} {1} {2} {3} {4} {5} 보너스 번호 {6}'.format(WinningNum[0], WinningNum[1], WinningNum[2], WinningNum[3], WinningNum[4], WinningNum[5], Bonus)) print('몇 장 구매하시겠습니까?') HowMany = int(input()) YourNum = [] Profit = HowMany * -1000 Count = 1 Result = [0, 0, 0, 0, 0, 0] while HowMany >= 1: HowMany -= 1 i = 0 j = 0 Correct = 0 isBonus = 0 random.shuffle(Lotto) YourNum = Lotto[0:6] YourNum.sort() while i <= 5: while j <= 5: if YourNum[i] == WinningNum[j]: Correct += 1 j += 1 i += 1 j = 0 i = 0 while i <= 5: if YourNum[i] == Bonus: isBonus = 1 i += 1 print('{0}번째 로또 : {1} {2} {3} {4} {5} {6}'.format(Count, YourNum[0], YourNum[1], YourNum[2], YourNum[3], YourNum[4], YourNum[5]), end='\t\t') if Correct <= 2: print('낙첨되었습니다') Result[5] += 1 elif Correct == 3: print('5등 당첨') Result[4] += 1 Profit += 5000 elif Correct == 4: print('4등 당첨') Result[3] += 1 Profit += 50000 elif Correct == 5: if isBonus == 0: print('3등 당첨') Result[2] += 1 Profit += 1390427 else: print('2등 당첨') Result[1] += 1 Profit += 5422666 elif Correct == 6: print('1등 당첨') Result[0] += 1 Profit += 195216000 Count += 1 print('최종 결과\n1등 : {0}회\n2등 : {1}회\n3등 : {2}회\n4등 : {3}회\n5등 : {4}회\n낙첨 : {5}회\n최종 금액 : {6}원'.format(Result[0], Result[1], Result[2], Result[3], Result[4], Result[5], Profit))
처음 짠 코드라 아주 난해하게 썼지만 굉장히 잘 작동함 제일 처음에는 당첨된 로또의 번호를 알려준다
입력 받는것은 몇장 살것인지 입력받고 출력되는것은 각 로또의 당첨 여부와 최종적으로 얼마의 손익을 봤는지 알림
이로써 알수있는건 로또로 최대 이익을 보기위해서는 적게사서 운좋게 당첨되는것 뿐이다
로또당첨되고싶다
'코딩' 카테고리의 다른 글
파이썬 requests로 만든 로또 번호 예측 (0) 2022.06.27 파이썬 List로 만든 숫자 한글 변환기 (0) 2022.06.14 파이썬 json으로 만든 인스타그램 DM txt파일로 내보내기 (0) 2022.06.02 파이썬 file write로 만든 ".py"파일 쉽게 만들기 (0) 2021.05.12 파이썬 file open으로 만든 카카오톡 단톡방 채팅 분석 (0) 2021.05.12