파이썬 조건 출력
조회수 702회
안녕하세요! rank_period_len
이 5
이상일 때는 값을 그대로 출력하고 5
미만일 때는 - 로 출력을 하고 싶어서 아래와 같이 코드를 짰더니 rank_period_len
이 다 -로 나오는데 어떻게 고치면 좋을까요?
현재 "rank_period_len": int(r[2])
로 int
타입입니다.
def get_table(rows):
collect = []
table = """"""
k = 'class = "active"'
j = 0
#여기 부분을 주로 보시면 될 것 같아요!
for i in rows:
rank_period_len = i["rank_period_len"]
if rank_period_len >= 5:
rank_period_len_str = rank_period_len
elif rank_period_len < 5:
rank_period_len_str = "-"
for i in rows:
if i["rank"] > 15:
table += f"""
<tr>
<td class="text-center">
<span>{i['rank']}</span>
</td>
<td class="text-center">
<span>{i['stock_name']}</span>
</td>
<td class="text-center">
<span>{rank_period_len_str}</span>
</td>
</tr>
"""
-> 출력하면 나오는 화면
<tr>
<td class="text-center">
<span>1</span>
</td>
<td class="text-center">
<span>삼성전자</span>
</td>
<td class="text-center">
<span>-</span>
-> 원래 삼성전자의 rank_period_len
값은 141
이에요!
답변주시면 감사하겠습니다 :)
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
댓글 입력