728x90
반응형
[ran01]
# 모듈 또는 라이브러리
import random
r1 = random.random()
print(r1)
# 0 <= r1 < 1
r2 = random.randint(1,45)
print(r2)
# 1 <= r2 <= 45
# 결과값
0.594889982070063
41
[ran02]로또_lotto
import random
def lotto():
lotto = []
i = 0
while i<6:
lotto.append(random.randint(1,45))
i += 1
print(lotto)
def lotto_t():
lot = set()
while len(lot) <6:
ran = random.randint(1,45)
lot.add(ran)
lst = sorted(lot) #sorted -> 자동으로 list로 바꿔줌(set은 순서가 없으니까)
print(lst)
if __name__ == '__main__':
lotto()
lotto_t()
# 결과값
[35, 10, 37, 18, 10, 8]
[3, 7, 24, 31, 32, 33]
728x90
반응형
'Language > Python' 카테고리의 다른 글
[python]math_원의 넓이 (0) | 2020.10.12 |
---|---|
[python]numpy, matplotlib_그래프 (0) | 2020.10.12 |
[python]lambda_람다, 익명함수 (0) | 2020.10.12 |
[python]함수02_구구단 (0) | 2020.10.08 |
[python]함수01 (0) | 2020.10.08 |