今回新規で使ったもの(lambda None True not and False import from assert)
p = lambda x:print(chr(10)+chr(13)+x) p("#lambda 2倍") hitBiscuit = lambda x:x*2 print(hitBiscuit(2)) p("#配列で2倍") hitBiscuit2 = lambda x:[x,x] print(hitBiscuit2(2)) print(hitBiscuit2(hitBiscuit2(2))) p("#None") a=[] print(a is None) print(a) a=None print(a is None) print(a) p("#1〜xのrange") range2=lambda x:[i for i in range(1,x+1)] print(sum(range2(10))) p("#True not and 素数") sosu = lambda x:x>=2 and len([i for i in range(2,x) if x%i==0])==0 s=[] for i in range2(100): if sosu(i)==True:s.append(i) print(s) ns=[] for i in range2(100): if not(sosu(i)==True):ns.append(i) print(ns) p("#False 素数でない数の割合1") c=0 for i in range2(1000): if sosu(i)==False:c+=1 print("1000まで",c/1000) #1行にしてみる print("10000まで", sum( [1 for i in range2(10000) if sosu(i)==False] ) /10000) p("#import from 素数でない数の割合2") from random import * c=0 for i in range2(1000): if sosu(randint(1,10000))==False:c+=1 print("10000までランダム抽出",c/1000) #1行にしてみる print("100000までランダム抽出",sum( [1 for i in range2(1000) if sosu(randint(1,100000))==False] )/1000) p("#assert") assert 1==2,"エラーしてみる"