커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
3-13 Flask로 로또 추천 사이트 만들기 2
[GPT] 웹개발 종합반 v0
3주차
북마크
댓글
4
추천
0
조회수
7
조회수
7
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.



강사님은 "0개 맞았습니다", "1개 맞았습니다", "2개 맞았습니다" 다 뜨는데 전 왜 5개 맞았습니다 에서 변동이 없을까요?


<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        text-align: center;
        font-family: Arial, sans-serif;
      }


      .lotto-numbers {
        list-style: none;
        padding: 0;
      }


      .lotto-numbers li {
        display: inline-block;
        margin: 5px;
        background-color: #ffff00;
        padding: 10px;
        border-radius: 50%;
        font-weight: bold;
      }


      .randomlotto-numbers {
        list-style: none;
        padding: 0;
      }


      .randomlotto-numbers li {
        display: inline-block;
        margin: 5px;
        background-color: red;
        padding: 10px;
        border-radius: 50%;
        font-weight: bold;
      }
    </style>
  </head>
  <body>
    <h1>안녕, {{data.name}}</h1>
    <h2>로또 번호: {{data.lotto}}</h2>
    <h2>랜덤 로또 번호: {{data.random_lotto}}</h2>
    <ul class="lotto-numbers">
      {% for element in data.lotto %}
      <li>{{ element|e }}</li>
      {% endfor %}
    </ul>
    <ul class="randomlotto-numbers">
      {% for element in data.random_lotto %}
      <li>{{ element|e }}</li>
      {% endfor %}
    </ul>
    <!-- 당첨 갯수에 따라 메세지 표시 -->
    {% if data.common_count == 6 %}
    <h2>{{data.common_count}}개 맞았습니다. 1등입니다!!</h2>
    {% elif data.common_count == 5 %}
    <h2>{{data.common_count}}개 맞았습니다. 2등입니다!!</h2>
    {% elif data.common_count == 4 %}
    <h2>{{data.common_count}}개 맞았습니다. 3등입니다!!</h2>
    {% elif data.common_count == 3 %}
    <h2>{{data.common_count}}개 맞았습니다. 4등입니다!!</h2>
    {% else %}
    <h2>{{data.common_count}}개 맞았습니다. 탈락입니다.</h2>
    {% endif %}
  </body>
</html>



import random
from flask import Flask, render_template
app = Flask(__name__)




@app.route('/')
def home():
  name = '김서연'
  lotto = [16, 18, 22, 43, 32, 11]
  
  def generate_lotto_numbers():
    numbers = random.sample(range(1, 45), 6)
    return sorted(numbers)
  random_lotto = generate_lotto_numbers()
  
  def count_common_elements(list1, list2):
    common_elements = set(list1) & set(list2)
    return len(common_elements)




  # 두 개의 리스트 예시
  common_count = count_common_elements(lotto, random_lotto)
  
  common_count = 5
  context = {
    'name': name,
    'lotto': lotto,
    'random_lotto':random_lotto,
    'common_count': common_count
  }
  
  return render_template('index.html', data=context)
  
if __name__ == "__main__": 
  app.run(debug=True, port=5001)



import random


def generate_lotto_numbers():
  numbers = random.sample(range(1, 46), 6)
  return sorted(numbers)


lotto_numbers = generate_lotto_numbers()
print("로또 추천 번호:", lotto_numbers)


def count_common_elements(list1, list2):
  common_elements = set(list1) & set(list2)
  return len(common_elements)


# 두 개의 리스트 예시
list1 = [1, 2, 3, 4, 9]
list2 = [4, 5, 6, 7, 8]


common_count = count_common_elements(list1, list2)
print("같은 요소의 개수:", common_count)
취소
 공유
취소
댓글 0
댓글 알림
나의얼굴