Last active
September 28, 2019 18:29
-
-
Save seven0525/89f0c12070131b4e832b70b878e7f221 to your computer and use it in GitHub Desktop.
「自作Python100本ノック」4日目(16本〜20本目) ref: https://qiita.com/ahpjop/items/c036a9dbc2f8b4a23c62
This file contains 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
from math import sin,pi | |
print(sin(pi/4)) #piは180°を表す |
This file contains 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
import binascii | |
#文字列 -> 16進数 | |
binascii.hexlify(b'Hello') | |
#16進数 -> 文字列 | |
binascii.unhexlify('48656c6c6f') |
This file contains 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
#英字(小文字&大文字):string.ascii_letters | |
#数字:string.digits | |
#記号:string.punctuation | |
import string | |
import random | |
a = ''.join([random.choice(string.ascii_letters + string.digits) for i in range(8)]) #リストの中の文字を連結出来る | |
print(a) |
This file contains 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
def randlist(size,lower,upper): | |
list = [] | |
for i in range(size): | |
list.append(random.randint(lower,upper)) | |
print(list) | |
randlist(10,30,90) |
This file contains 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
def check_hand(a,b,c,d,e): | |
list_hands = [a,b,c,d,e] | |
dict_hands = {0 : "NO PAIR", 1 : "ONE PAIR", 2 : "TWO PAIR", 3 : "THREE CARD", 4 : "FOUR CARD", 5 : "FULL HOUSE"} | |
results = [] | |
for i in list_hands:#カードXを選ぶ | |
count_i = list_hands.count(i)#手札の中にあるカードXの個数をカウント | |
left_hands = [n for n in list_hands if n != i] #Xの数字を除いた残りの手札 | |
for j in left_hands:#X以外の数字のカードからカードYを選ぶ | |
count_j = list_hands.count(j)#手札の中にあるカードYの個数をカウント | |
if count_i == 2 and count_j < 2: | |
results.append(1) | |
elif count_i == 2 and count_j == 2: | |
results.append(2) | |
elif count_i == 3 and count_j == 1: | |
results.append(3) | |
elif count_i == 4 and count_j == 1 : | |
results.append(4) | |
elif count_i == 3 and count_j == 2 : | |
results.append(5) | |
else: | |
results.append(0) | |
result = max(results) | |
return dict_hands[result] | |
check_hand(10,8,11,11,4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment