728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
from django.shortcuts import render
# Create your views here.
def index(request):
import random
import requests
n1 = 0
n2 = 0
n3 = 0
n4 = 0
n5 = 0
url = 'https://dhlottery.co.kr/common.do?method=getLottoNumber'# 바꿔야함
response = requests.get(url).json()
for _ in range(1000):
total = 0
bo = 0
numbers = random.sample(range(1,47),6)
if response.get('drwtNo1') in numbers:
total += 1
if response.get('drwtNo2') in numbers:
total += 1
if response.get('drwtNo3') in numbers:
total += 1
if response.get('drwtNo4') in numbers:
total += 1
if response.get('drwtNo5') in numbers:
total += 1
if response.get('drwtNo6') in numbers:
total += 1
if response.get('bnusNo') in numbers:
bo += 1
if total == 6:
n1 += 1
elif total == 5 and bo == 1:n2+=1
elif total == 5: n3+=1
elif total == 4: n4+=1
elif total == 3: n5+=1
elif total == 2: n6+=1
elif total == 1: n7+=1
rest = 1000-n1-n2-n3-n4-n5
context = {
'drwtNo1':response.get('drwtNo1'),
'drwtNo2':response.get('drwtNo2'),
'drwtNo3':response.get('drwtNo3'),
'drwtNo4':response.get('drwtNo4'),
'drwtNo5':response.get('drwtNo5'),
'drwtNo6':response.get('drwtNo6'),
'bnusNo':response.get('bnusNo'),
'n1':n1,
'n2':n2,
'n3':n3,
'n4':n4,
'n5':n5,
'rest':rest,
}
return render(request,'lotto/index.html', context)
|
cs |
api 를 적용시키는 것, 하지만 난 못한 것, 언제 이해할수 있을지 미지수입니다.
728x90
반응형
'SSAFY > Django' 카테고리의 다른 글
Django 가상 환경 만들기 // 협업 (0) | 2021.03.13 |
---|---|
Django 관통 Prj (0) | 2021.03.13 |
게시판 만들기 ( 수정 삭제 기능 구현!) (0) | 2021.03.11 |
DATEBASE <--> Django (2) | 2021.03.10 |
Django 시작하기 (2) | 2021.03.08 |