Last active
July 19, 2017 02:30
-
-
Save Pusungwi/cda0846a5dbe4226762d058efb352745 to your computer and use it in GitHub Desktop.
귀찮다 다 귀찮아 파이썬아 골라줘라
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#encoding=utf-8 | |
#귀찮은 닝겐들을 위한 선택기 | |
#게임이든 밥이든 귀찮을떄 파이썬 랜덤신한테 빌어봅시다. | |
#쓴놈 : Yeonjae Lee | |
#사용 방법 예 : 미국트럭과 망타2, 건-젼, 스타2 중에서 무슨 게임을 해야 할지 모르겠고 5번 먼저 걸린 게임을 하고 싶다. 하면 | |
#choice_please(['미국트럭', '망타2', '건-젼', '스타2'], 5) 라고 고치고 컨트롤 + 엔터 누르시면 됩니다. | |
#먼저 걸린 대상 수를 너무 많이 넣으면 Killed 메세지가 나오면서 실행이 안될 수 있습니다. (10000번까진 해봤습니다.) | |
#CPython 3.6.1에서 정상동작 확인 | |
#예제 : https://wandbox.org/permlink/1mw56RPDJ9hGk9KM | |
import random | |
def choice_please(target_list, success_count = 1): | |
count_dict = {} | |
while True: | |
tmp_result = random.choice(target_list) | |
tmp_count = 0 | |
if tmp_result in count_dict.keys(): | |
tmp_count = count_dict[tmp_result] | |
tmp_count = tmp_count + 1 | |
count_dict[tmp_result] = tmp_count | |
if tmp_count == success_count: | |
print('결과 : ' + str(count_dict)) | |
print('선택받은 자 : ' + tmp_result) | |
break | |
if __name__ == '__main__': | |
choice_please(['피자', '서브웨이 30cm', '라면'], 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment