<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>zinc_96.log</title>
        <link>https://velog.io/</link>
        <description>내 꿈은 멋쟁이개발자</description>
        <lastBuildDate>Wed, 04 Aug 2021 07:20:24 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>zinc_96.log</title>
            <url>https://images.velog.io/images/zinc_96/profile/f281123e-4bae-4dfe-9dc6-b135b619e244/social.png</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. zinc_96.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/zinc_96" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[Python 문자열 활용 심화]]></title>
            <link>https://velog.io/@zinc_96/Python-%EB%AC%B8%EC%9E%90%EC%97%B4-%ED%99%9C%EC%9A%A9-%EC%8B%AC%ED%99%94</link>
            <guid>https://velog.io/@zinc_96/Python-%EB%AC%B8%EC%9E%90%EC%97%B4-%ED%99%9C%EC%9A%A9-%EC%8B%AC%ED%99%94</guid>
            <pubDate>Wed, 04 Aug 2021 07:20:24 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="11일차">11일차</h2>
<h3 id="문자열-심화-문제">문자열 심화 문제</h3>
<ol>
<li>문자열을 입력받고, 괄호가 잘 닫혀있는 문장인지 점검</li>
</ol>
<ul>
<li>문장 내에서 괄호는 무조건 &#39;(&#39;로 시작하고 &#39;)&#39;로 끝나야 한다.</li>
<li>ex. hell(o, my name (is zin)c!)</li>
</ul>
<blockquote>
<p>replace(), split()</p>
</blockquote>
<pre><code class="language-py">user = input()

u = user.replace(&#39;(&#39;,&#39; ( &#39;).replace(&#39;)&#39;,&#39; ) &#39;)
x = u.split(&#39; &#39;)

print(x)

n = 0

for i in x:
    if n &lt; 0:
        break
    elif i == &#39;(&#39;:
        n += 1
    elif i == &#39;)&#39;:
        n -= 1

if n == 0:
    print(&quot;괄호가 잘 닫혀있는 문장입니다.&quot;)
else:
    print(&quot;괄호가 잘 닫혀있지 않는 문장입니다.&quot;)</code></pre>
<ul>
<li><code>user.replace(&#39;(&#39;,&#39; ( &#39;).replace(&#39;)&#39;,&#39; ) &#39;)</code> : 공백으로 나눠주기 위해 대체해준다.</li>
<li><code>if n &lt; 0: break</code> : 음수가 나온다는 것은 &#39;)&#39;가 &#39;(&#39; 보다 먼저 나왔거나 더 많이 존재한다는 것이기 때문에 <code>break</code>를 해준다.</li>
</ul>
<hr>
<ol start="2">
<li>영어 끝말잇기 프로그램 / 실패할 경우 종료<blockquote>
<p>인덱싱</p>
</blockquote>
</li>
</ol>
<pre><code class="language-py">user = input(&quot;끝말잇기 시작 : &quot;)

while 1:
    print(f&quot;{user} -&gt; &quot;, end=&#39;&#39;)
    next = input()

    if user[-1] == next[0]:
        pass
    else:
        print(&quot;game over!&quot;)
        break

    user = next</code></pre>
<ul>
<li>첫 단어의 마지막 글자를 인덱싱 : <code>user[-1]</code></li>
<li>다음 단어의 첫 글자를 인덱싱 : <code>next[0]</code></li>
<li><code>while</code>문 마지막에 <code>user = next</code>해줌으로써 단어를 넘겨주는 과정이 필요하다.</li>
</ul>
<hr>
<ol start="3">
<li>1에서 N까지 이어서 적었을 때 문자열의 길이를 구하여라<blockquote>
<p>len()</p>
</blockquote>
</li>
</ol>
<pre><code class="language-py">N = int(input(&quot;수 입력 : &quot;))

x =&#39;&#39;

for i in range(1, N+1):
    x += str(i)

print(len(x))</code></pre>
<ul>
<li>N을 int형으로 받아줬기 때문에 <code>str(i)</code>로 형변환을 해주는 과정이 필요하다.</li>
<li>문자열은 더하기 연산을 해주면 이어서 붙는다는 성질을 활용한다.</li>
</ul>
<hr>
<ol start="4">
<li>주민번호를 통해 남성과 여성의 비율을 구하여라<blockquote>
<p>split(), 인덱싱</p>
</blockquote>
</li>
</ol>
<pre><code class="language-py">num = [&#39;150612-2******&#39;, &#39;020900-2******&#39;, &#39;910519-1******&#39;, &#39;130218-2******&#39;, &#39;130103-3******&#39;, &#39;910316-0******&#39;, &#39;970720-1******&#39;, &#39;130717-3******&#39;, &#39;070203-3******&#39;, &#39;820114-1******&#39;, &#39;910018-1******&#39;, &#39;980803-0******&#39;, &#39;820600-1******&#39;, &#39;130628-3******&#39;, &#39;150902-2******&#39;, &#39;970220-0******&#39;, &#39;830924-1******&#39;, &#39;090712-3******&#39;, &#39;901011-1******&#39;, &#39;190910-3******&#39;, &#39;861203-1******&#39;, &#39;070704-3******&#39;, &#39;970505-0******&#39;, &#39;020222-3******&#39;, &#39;810501-1******&#39;, &#39;160326-2******&#39;, &#39;190611-3******&#39;, &#39;200506-3******&#39;, &#39;100410-2******&#39;, &#39;970028-0******&#39;, &#39;851213-0******&#39;, &#39;850418-1******&#39;, &#39;031210-2******&#39;, &#39;090113-3******&#39;, &#39;810902-1******&#39;, &#39;030726-3******&#39;, &#39;020126-3******&#39;, &#39;910215-1******&#39;, &#39;081006-3******&#39;, &#39;871209-0******&#39;, &#39;170927-2******&#39;]

w = 0
m = 0

for i in num:
    nums = i.split(&#39;-&#39;)[1]

    if int(nums[0]) % 2 == 0:
        w += 1
    else :
        m += 1

wp = w / (w+m) * 100
mp = m / (w+m) * 100

print(f&quot;여성 : {wp}%, 남성 : {mp}%&quot;)</code></pre>
<ul>
<li><code>nums = i.split(&#39;-&#39;)[1]</code> : &#39;-&#39;로 나눠준 후 인덱싱을 활용하여 1번 자리의 요소를 불러온다.</li>
<li>예를 들어 &#39;2<strong>**</strong>&#39; 이런식으로 불러와지기 때문에 <code>int(nums[0])</code>로 &#39;2&#39;만 가져와서 정수형으로 형변환 시켜준다.</li>
</ul>
<hr>
<h3 id="문자열--set">문자열 + set</h3>
<blockquote>
<p>set : 중복을 제거하는 함수</p>
</blockquote>
<ol>
<li>노래가사에서 단어를 분리해서 중복을 제거하여라</li>
</ol>
<pre><code class="language-py">music = &quot;&quot;&quot;Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shoes on get up in the morn
Cup of milk let&#39;s rock and roll
King Kong kick the drum rolling on like a rolling stone
Sing song when I&#39;m walking home
Jump up to the top LeBron
Ding dong call me on my phone
Ice tea and a game of ping pong
This is getting heavy
Can you hear the bass boom, I&#39;m ready
Life is sweet as honey
Yeah this beat cha ching like money
Disco overload I&#39;m into that I&#39;m good to go
I&#39;m diamond you know I glow up
Hey, so let&#39;s go
Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah
Bring a friend join the crowd
Whoever wanna come along
Word up talk the talk just move like we off the wall
Day or night the sky&#39;s alight
So we dance to the break of dawn
Ladies and gentlemen,
I got the medicine so you should keep ya eyes on the ball, huh
This is getting heavy
Can you hear the bass boom, I&#39;m ready
Life is sweet as honey
Yeah this beat cha ching like money
Disco overload I&#39;m into that I&#39;m good to go
I&#39;m diamond you know I glow up
Let&#39;s go
Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah
Dynnnnnanana, life is dynamite
Dynnnnnanana, life is dynamite
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah
Dynnnnnanana eh
Dynnnnnanana eh
Dynnnnnanana eh
Light it up like dynamite
Dynnnnnanana eh
Dynnnnnanana eh
Dynnnnnanana eh
Light it up like dynamite
Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite
Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah
Dynnnnnanana, life is dynamite
Dynnnnnanana, life is dynamite
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah&quot;&quot;&quot;

m = music.replace(&#39;\n&#39;, &#39; &#39;).replace(&#39;,&#39;,&#39;&#39;).split(&#39; &#39;)

for i in set(m):
    print(f&quot;{i}가 나오는 횟수 : {m.count(i)}&quot;)</code></pre>
<ul>
<li><code>set(m)</code> : 노래가사를 단어로 분리해주고 거기서 중복된 것을 제거한 결과이다.</li>
</ul>
<hr>
<ol start="2">
<li>N회를 입력받고, 로또번호를 출력하는 프로그램</li>
</ol>
<ul>
<li>set()으로 초기화, add()로 추가</li>
<li>a = set() : a라는 세트 선언 (초기확)</li>
<li>a.add(1) : a세트에 1추가</li>
</ul>
<pre><code class="language-py">import random

N = int(input(&quot;횟수 입력 : &quot;))

for i in range(1, N+1):

    x = set()

    while 1:
        ran = random.randint(1, 45)
        x.add(ran)

        if len(x) == 6:
            break

    print(f&quot;{i}회 당첨번호는 {x}&quot;)</code></pre>
<hr>
<h3 id="문자열--dictionary">문자열 + dictionary</h3>
<blockquote>
<p>dictionary : 사전   </p>
</blockquote>
<ul>
<li>노래가사의 단어들의 중복을 제거해서 <em>dictionary에 단어 : 단어등장횟수</em> 로 저장.</li>
<li><code>a[1] = &quot;four&quot;</code> : a라는 사전에 <code>1 : &quot;four&quot;</code> 이런식으로 저장된다.</li>
</ul>
<pre><code class="language-py">music = &quot;&quot;&quot;Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shoes on get up in the morn
Cup of milk let&#39;s rock and roll
King Kong kick the drum rolling on like a rolling stone
Sing song when I&#39;m walking home
Jump up to the top LeBron
Ding dong call me on my phone
Ice tea and a game of ping pong
This is getting heavy
Can you hear the bass boom, I&#39;m ready
Life is sweet as honey
Yeah this beat cha ching like money
Disco overload I&#39;m into that I&#39;m good to go
I&#39;m diamond you know I glow up
Hey, so let&#39;s go
Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah
Bring a friend join the crowd
Whoever wanna come along
Word up talk the talk just move like we off the wall
Day or night the sky&#39;s alight
So we dance to the break of dawn
Ladies and gentlemen,
I got the medicine so you should keep ya eyes on the ball, huh
This is getting heavy
Can you hear the bass boom, I&#39;m ready
Life is sweet as honey
Yeah this beat cha ching like money
Disco overload I&#39;m into that I&#39;m good to go
I&#39;m diamond you know I glow up
Let&#39;s go
Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah
Dynnnnnanana, life is dynamite
Dynnnnnanana, life is dynamite
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah
Dynnnnnanana eh
Dynnnnnanana eh
Dynnnnnanana eh
Light it up like dynamite
Dynnnnnanana eh
Dynnnnnanana eh
Dynnnnnanana eh
Light it up like dynamite
Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite
Cos ah ah I&#39;m in the stars tonight
So watch me bring the fire and set the night alight
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah
Dynnnnnanana, life is dynamite
Dynnnnnanana, life is dynamite
Shining through the city with a little funk and soul
So I&#39;mma light it up like dynamite, woah&quot;&quot;&quot;

m = music.replace(&#39;\n&#39;, &#39; &#39;).replace(&#39;,&#39;, &#39;&#39;).split(&#39; &#39;)

dynamite = {}

for i in set(m):
    dynamite[i] = m.count(i)

for i in dynamite:
    print(f&quot;key = {i} : value = {dynamite[i]}&quot;)</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python 문자열 활용]]></title>
            <link>https://velog.io/@zinc_96/Python-%EB%AC%B8%EC%9E%90%EC%97%B4-%ED%99%9C%EC%9A%A9</link>
            <guid>https://velog.io/@zinc_96/Python-%EB%AC%B8%EC%9E%90%EC%97%B4-%ED%99%9C%EC%9A%A9</guid>
            <pubDate>Sat, 31 Jul 2021 14:07:29 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="10일차">10일차</h2>
<h3 id="문자열-활용">문자열 활용</h3>
<table>
<thead>
<tr>
<th align="center">명칭</th>
<th align="center">뜻</th>
<th align="center">표현형</th>
</tr>
</thead>
<tbody><tr>
<td align="center">split</td>
<td align="center">특정 기호를 기준으로 문자열을 잘라주는 기능</td>
<td align="center">.split(&#39;특정 기호&#39;)</td>
</tr>
<tr>
<td align="center">replace</td>
<td align="center">문자열(a)을 다른 문자열(b)로 바꿔주는 기능</td>
<td align="center">.replace(&#39;a&#39;,&#39;b&#39;)</td>
</tr>
<tr>
<td align="center">count</td>
<td align="center">해당 문자(a) 개수 세기</td>
<td align="center">.count(&#39;a&#39;)</td>
</tr>
<tr>
<td align="center">strip</td>
<td align="center">불필요한 공백 제거</td>
<td align="center">.strip()</td>
</tr>
<tr>
<td align="center">lstrip</td>
<td align="center">왼쪽 공백 제거</td>
<td align="center">.lstrip()</td>
</tr>
<tr>
<td align="center">rstrip</td>
<td align="center">오른쪽 공백 제거</td>
<td align="center">.rstrip()</td>
</tr>
<tr>
<td align="center">upper</td>
<td align="center">대문자 전환</td>
<td align="center">.upper()</td>
</tr>
<tr>
<td align="center">lower</td>
<td align="center">소문자 전환</td>
<td align="center">.lower()</td>
</tr>
</tbody></table>
<h3 id="문자열-활용-예제">문자열 활용 예제</h3>
<ol>
<li>포켓몬 이름 정리하기</li>
</ol>
<blockquote>
<p>리스트에 번호와 공백과 함께 저장되어 있는 포켓몬 이름을 오직 포켓몬 이름만 출력되게 정리하기</p>
</blockquote>
<pre><code class="language-py">poke = [&#39;1.이상해씨 &#39;, &#39;2.이상해풀 &#39;, &#39;3.이상해꽃 &#39;, &#39;4.파이리 &#39;, &#39;5.리자드 &#39;]

pokename = []

for i in poke:
    pokename.append(i.split(&#39;.&#39;)[1].strip())

print(pokename)</code></pre>
<ul>
<li>리스트 내에 더 많은 정보가 들어있더라도 정리할 수 있다.</li>
<li><code>for</code>문을 통해 리스트 요소 하나하나를 <code>i</code>에 받아온다.</li>
<li><code>i.split(&#39;.&#39;)</code> : <strong>&#39;1.이상해씨 &#39; -&gt; &#39;1&#39;,&#39;이상해씨 &#39;</strong> 로 나눌 수 있다.</li>
<li>포켓몬의 이름만 받기 위해서 인덱싱을 활용하여 <code>i.split(&#39;.&#39;)[1]</code>을 해주면 첫번째 요소인 번호, 두번째 요소인 포켓몬 이름 중에서 포켓몬 이름을 받아 올 수 있다.</li>
<li><code>strip()</code> : <strong>&#39;이상해씨 &#39;</strong> 받아온 이름에서 공백을 없애줘야하기 때문에 필요없는 공백을 없애주기 위해 사용한다.</li>
<li><code>i.split(&#39;.&#39;).strip()</code> : 최종으로 이렇게 작성해주면 원하는 부분을 얻어 올 수 있다.</li>
</ul>
<hr>
<ol start="2">
<li>전화번호부에서 서울 사는 사람 구하기</li>
</ol>
<blockquote>
<p>나열되어 있는 여러개의 전화번호를 리스트로 나누어 담고 거기서 &#39;02&#39;로 시작하는 전화번호를 찾아서 세면 된다.</p>
</blockquote>
<pre><code class="language-py"># case 1
tel = &quot;051-467-3812,063-415-6555,02-344-2750,010-469-5158,02-675-9945&quot;

tels = tel.split(&#39;,&#39;)
seoult = []

for i in tels:
    if i.split(&#39;-&#39;)[0] == &#39;02&#39;:
        seoult.append(i)

print(&quot;서울 사는 사람 수 : &quot;, len(seoult))</code></pre>
<ul>
<li><code>split(&#39;-&#39;)[0] == 02</code>를 통해 서울 전화번호를 <code>seoult</code>리스트에 추가해주고</li>
<li><code>(len)seoult</code> : 리스트의 길이를 구해 서울 사는 사람 수를 구할 수 있다.</li>
</ul>
<pre><code class="language-py"># case 2
지역번호 = []

for i in tels:
    지역번호.append(tels.split(&#39;-&#39;)[0])

print(&quot;서울 사는 사람 수 : &quot;, 지역번호.count(&#39;02&#39;))</code></pre>
<ul>
<li><code>split(&#39;-&#39;)[0]</code> 로 지역번호만 저장하는 list를 만들어서</li>
<li><code>count(&#39;02&#39;)</code> 로 서울 지역번호의 개수를 count한다.</li>
</ul>
<hr>
<ol start="3">
<li>메뉴판에서 제품명 출력하기<blockquote>
<p>금액을 입력받고, 그 금액으로 구매 가능한 제품명을 출력하게 한다.</p>
</blockquote>
</li>
</ol>
<pre><code class="language-py">money = int(input(&quot;돈을 넣어주세요 : &quot;))
Menu = &quot;딸기 4000원\t파인애플 5000원\t포도 4000원\t사과 2000원\t감자 3000원\n수박 8000원\t감귤 4000원\t한라봉 7000원\t체리 3000원\t자두 2000원\n아메리카노 3000원\t카페라떼 4000원\t카페모카 4500원\t아인슈패너 6000원\n에스프레소 2000원\t카푸치노 3600원\t아이스티 3000원\t레몬에이드 4000원\n초코우유 1500원\t딸기우유 1500원\t바나나우유 1500원\t커피우유 1500원\n두유 2000원\t헤이즐넛 3000원\t오레오초코 4000원\t얼그레이 6000원&quot;

menu = Menu.replace(&#39;\n&#39;,&#39;\t&#39;)
menu = menu.split(&#39;\t&#39;)

for i in menu:
    x = i.split(&#39; &#39;)

    if money &gt;= int(x[1][:-1]):
        print(&quot;구매 가능한 과일 : &quot;, x[0])</code></pre>
<ul>
<li><code>replace(&#39;\n&#39;,&#39;\t&#39;)</code> 로 나눠줄 특정 기호를 통일해준다.</li>
<li><code>split(&#39; &#39;)[1]</code> 로만 하면 &#39;4000&#39;이 아니라 &#39;4000원&#39; 으로 저장되기 때문에</li>
<li><code>x[1][:-1]</code> 문자열 슬라이싱을 활용하여 맨 마지막 문자 전까지 저장하게끔 해준다.</li>
<li>하지만 문자로 저장된 것이기 때문에 자료형을 바꿔주어야 해서 <code>int(x[1][:1])</code>까지 처리한다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python 랜덤연산게임]]></title>
            <link>https://velog.io/@zinc_96/Python-%EB%9E%9C%EB%8D%A4%EC%97%B0%EC%82%B0%EA%B2%8C%EC%9E%84</link>
            <guid>https://velog.io/@zinc_96/Python-%EB%9E%9C%EB%8D%A4%EC%97%B0%EC%82%B0%EA%B2%8C%EC%9E%84</guid>
            <pubDate>Wed, 28 Jul 2021 09:49:28 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="9일차">9일차</h2>
<h3 id="랜덤연산게임"><strong>랜덤연산게임</strong></h3>
<blockquote>
<p><code>import random</code> 사용<br>랜덤으로 뽑은 두 수의 덧셈과 뺄셈 문제가 반복적으로 나오는 프로그램</p>
</blockquote>
<ul>
<li>20%의 확률로 200점 짜리 문제가 나오고 25%의 확률로 목숨 2개 짜리 문제가 나오게 한다.</li>
<li>쉬움(한자리 수 연산), 노멀(두자리 수 연산), 어려움(세자리 수 연산)으로 <strong>난이도 조정</strong>을 한다.</li>
<li>Game out이 될 경우 사용자에게 다시 할 건지 물어보고 yes로 답할 경우 난이도 설정부터 다시 반복되도록 한다.</li>
</ul>
<pre><code class="language-py">
import random
import os
import time

while 1:
    life = 5
    score = 0
    nan = int(input(&quot;난이도 선택 1. 쉬움, 2. 노멀, 3. 어려움 : &quot;))

    if nan == 1:
        r1 = 1
        r2 = 9
    elif nan == 2:
        r1 = 10
        r2 = 99
    else :
        r1 = 100
        r2 = 999

    while 1:
        print(&quot;현재 점수 : {}, 현재 목숨 : {}&quot;.format(score, life))
        if life &lt;= 0:                   
            break

        A = random.randint(r1, r2)
        B = random.randint(r1, r2)

        op = random.randint(0,1)  
        l2 = random.randint(1,4)    
        s200 = random.randint(1,5)  

        if l2 == 1:
            print(&quot;목숨 2개 짜리 문제&quot;)
            목숨 = 2                    
        else :
            목숨 = 1

        if s200 == 1:
            print(&quot;200점 짜리 문제&quot;)
            점수 = 200
        else :
            점수 = 100

        if op == 0:
            user = int(input(&quot;{} + {} = &quot;.format(A,B)))
            C = A+B
        else :
            user = int(input(&quot;{} - {} = &quot;.format(A,B)))
            C = A-B

        if user == C:
            score += 점수
            print(&quot;정답입니다.&quot;)
        else : 
            life -= 목숨
            print(&quot;오답입니다.&quot;)

        time.sleep(1)
        os.system(&#39;cls&#39;)

    x = input(&quot;다시 게임을 시작하시겠습니까? (y/n) : &quot;)
    if x == &#39;n&#39;:        
        print(&quot;게임 종료!&quot;)     
        break
</code></pre>
<ul>
<li><code>A = random.randint(r1, r2)</code> : 범위를 미리 지정한 변수를 대입 해서 랜덤 함수를 반복해서 점검할 필요 없이 처리해준다.</li>
<li><code>op = random.randint(0,1)</code> : 덧셈(0), 뺄셈(1)로 지정해서 랜덤 함수 사용</li>
<li><code>l2 = random.randint(1,4)</code> : 1~4까지의 수 중 하나를 목숨 두개 문제로 지정하면 25% 확률로 다룰 수 있다.</li>
<li><code>s200 = random.randint(1,5)</code> : 1~5까지의 수 중 하나를 200점 문제로 지정하면 20% 확률로 다룰 수 있다.</li>
<li><code>if l2 == 1</code> : if문에서 <code>목숨 = 2</code> 이렇게 변수로 저장을 해준 뒤 <code>if user == C</code> 답을 비교해주는 구문에서 처리해준다.</li>
<li><code>x = input(&quot;다시 게임을 시작하시겠습니까? (y/n) : &quot;)</code> 게임이 끝난 후에 물어봐야하기에 while문 내부의 while문이 break된 후에 작성해 준다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python 업다운게임]]></title>
            <link>https://velog.io/@zinc_96/Python-%EC%97%85%EB%8B%A4%EC%9A%B4%EA%B2%8C%EC%9E%84</link>
            <guid>https://velog.io/@zinc_96/Python-%EC%97%85%EB%8B%A4%EC%9A%B4%EA%B2%8C%EC%9E%84</guid>
            <pubDate>Wed, 28 Jul 2021 09:46:40 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="8일차">8일차</h2>
<h3 id="업다운-게임"><strong>업다운 게임</strong></h3>
<blockquote>
<p><code>import random</code> 사용<br>사용자에게 수를 입력받고 사용자의 대답에 따라 up, down, correct 세가지 상황을 판별하는 프로그램</p>
</blockquote>
<ul>
<li>몇번만에 정답을 맞췄는지도 함께 고려한다.</li>
</ul>
<pre><code class="language-py">import random
import os
import time

N = random.randint(10,99)
count = 0

while 1:
    user = int(input(&quot;두 자리 수 입력 : &quot;))
    count += 1

    if user &gt; N:
        print(&quot;down!&quot;)
    elif user &lt; N :
        print(&quot;up!&quot;)
    else:
        print(&quot;correct!!!&quot;)
        break

    time.sleep(2)
    os.system(&#39;cls&#39;)    

print(&quot;{}번 만에 맞췄습니다.&quot;.format(count))</code></pre>
<ul>
<li><code>random</code>을 반복문 내부에 둬야하는지 외부에 둬야하는지 잘 생각해야한다.</li>
<li>고정된 답을 가지고 맞추는 문제이기 때문에 반복문 외부에 <code>random</code>함수를 작성한다.</li>
<li><code>count +=1</code> : 반복문이 돌아갈 때 마다 1씩 더해줘야한다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python 홀짝판단게임]]></title>
            <link>https://velog.io/@zinc_96/Python-%ED%99%80%EC%A7%9D%ED%8C%90%EB%8B%A8%EA%B2%8C%EC%9E%84</link>
            <guid>https://velog.io/@zinc_96/Python-%ED%99%80%EC%A7%9D%ED%8C%90%EB%8B%A8%EA%B2%8C%EC%9E%84</guid>
            <pubDate>Wed, 28 Jul 2021 09:44:22 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="7일차">7일차</h2>
<h3 id="홀짝판단-게임"><strong>홀짝판단 게임</strong></h3>
<blockquote>
<p><code>import random</code> 사용<br>사용자에게 홀, 짝을 입력받고 random으로 정해진 값과 비교하여 결과를 내는 게임</p>
</blockquote>
<ul>
<li>정답일 경우 점수 +100</li>
<li>오답일 경우 목숨 -1</li>
<li>목숨이 0이 될 때 게임 종료</li>
</ul>
<pre><code class="language-py">import random
import os
import time


life = 5
score = 0

while 1:
    if life == 0:
        print(&quot;게임 종료&quot;)
        break

    N = random.randint(10,99)
    print(&quot;점수 : {}, 목숨 : {}&quot;.format(score, life))
    user = int(input(&quot;홀(0), 짝(1) : &quot;))

    print(&quot;정답 : {}&quot;.format(N), end=&#39;/ &#39;)

    if user:
        if N % 2:
            print(&quot;틀렸습니다.&quot;)
            life -= 1
        else:
            print(&quot;맞았습니다.&quot;)
            score += 100
    else:
        if N % 2:
            print(&quot;맞았습니다.&quot;)
            score += 100
        else:
            print(&quot;틀렸습니다.&quot;)
            life -= 1

    time.sleep(2)               # 프로그램을 잠시 멈춤
    os.system(&quot;cls&quot;)            # 화면을 바꿔줌

print(&quot;총 점수 : &quot;, score)</code></pre>
<ul>
<li>게임의 효과를 내기 위해서 <code>import time</code>과 <code>import os</code>사용</li>
<li><code>N = random.randint(10,99)</code> : 10~99까지의 수 중에서 랜덤으로 수 하나를 뽑는다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python while]]></title>
            <link>https://velog.io/@zinc_96/Python-while</link>
            <guid>https://velog.io/@zinc_96/Python-while</guid>
            <pubDate>Tue, 27 Jul 2021 12:03:13 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="6일차">6일차</h2>
<h3 id="while문">while문</h3>
<hr>
<blockquote>
<p>while문 예제</p>
</blockquote>
<ol>
<li>for vs while 구구단 출력<pre><code class="language-py"># for
for i in range(2, 10):
 for j in range(1, 10):
     print(&quot;{} x {} = {}&quot;.format(i,j,i*j))
 print()
</code></pre>
</li>
</ol>
<h1 id="while">while</h1>
<p>i = 2
while i &lt; 10:
    j = 1
    while j &lt; 10:
        print(&quot;{} x {} = {}&quot;.format(i,j,i*j))
        j += 1
    i += 1
    print()</p>
<pre><code>* `.format()`을 사용하면 보다 자연스럽게 출력을 작성 할 수 있다.
* while은 i,j를 직접 지정을 해줘야 한다.

2. 사용자가 0을 입력할 때까지 반복하기

```py
while 1:
    su = int(input(&quot;수 입력 : &quot;))
    if su == 0:
        break</code></pre><ul>
<li>while True: (무한 반복), while 1: (무한 반복)</li>
</ul>
<ol start="3">
<li>사용자가 q 를 입력할 때까지 반복하기</li>
</ol>
<pre><code class="language-py">while 1:
    user = input(&quot;q 입력하면 종료 : &quot;)
    if user == &#39;q&#39;:
        break</code></pre>
<ul>
<li>q는 문자이기 때문에 <code>int(input())</code>이 아니라 <code>input()</code>그대로 작성해준다.</li>
</ul>
<ol start="4">
<li>q를 누를때까지 숫자들을 리스트에 담는것</li>
</ol>
<pre><code class="language-py">li = []

while 1:
    user = input(&quot;수 입력(q를 입력하면 종료): &quot;)
    if user == &#39;q&#39;:
        break
    li.append(int(user))

print(li)</code></pre>
<ul>
<li>문자를 입력하면 종료되는 부분 : <code>input()</code></li>
<li>숫자들을 리스트에 담는 부분 : <code>li.append(int(user))</code></li>
<li>if문의 순서가 중요하다. <code>li.append()</code>보다 뒤에 작성되면 <code>user</code>를 <code>int(user)</code>로 형변환을 시켜줬기 때문에 에러가 난다.</li>
</ul>
<ol start="5">
<li>종료를 누를때까지 숫자들의 합을 출력<pre><code class="language-py">li = []
</code></pre>
</li>
</ol>
<p>while 1:
    user = input(&quot;수 입력(q를 입력하면 종료): &quot;)
    if user == &#39;q&#39;:
        break
    li.append(int(user))</p>
<p>print(&quot;{} 이 값들의 총 합은 : {}&quot;.format(li, sum(li)))</p>
<pre><code>
6. 종료를 누를때까지 숫자들의 평균을 출력

```py
li = []

while 1:
    user = input(&quot;수 입력(q를 입력하면 종료): &quot;)
    if user == &#39;q&#39;:
        break
    li.append(int(user))

avg = sum(li)/len(li)
print(avg)</code></pre><ol start="7">
<li>종료를 누를때까지 숫자들의 평균, 그 이상인 숫자들 출력<pre><code class="language-py">li = []
</code></pre>
</li>
</ol>
<p>while 1:
    user = input(&quot;수 입력(q를 입력하면 종료): &quot;)
    if user == &#39;q&#39;:
        break
    li.append(int(user))</p>
<p>avg = sum(li)/len(li)
print(avg)</p>
<pre><code>* 여기까지는 평균을 구하는 예제와 같다.

```py
for i in li:
    if i &gt;= avg:
        print(i)</code></pre><ul>
<li>범위가 정해져 있을 때 유용한 for문을 통해서 평균 이상의 수들을 출력하는 구문을 작성한다.</li>
<li>for문과 while문을 적절히 섞어가며 구문을 작성할 수 있다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python for 심화]]></title>
            <link>https://velog.io/@zinc_96/Python-for-%EC%8B%AC%ED%99%94</link>
            <guid>https://velog.io/@zinc_96/Python-for-%EC%8B%AC%ED%99%94</guid>
            <pubDate>Tue, 27 Jul 2021 11:13:24 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="5일차">5일차</h2>
<h3 id="for문-심화">for문 심화</h3>
<hr>
<blockquote>
<p>윤년 구하는 프로그램, 완전수, 소수 판단 프로그램</p>
</blockquote>
<h3 id="윤년-프로그램"><strong>윤년 프로그램</strong></h3>
<blockquote>
<p>윤년은 해당 연도를 4로 나눴을때 나누어 떨어지면 윤년입니다.<br>하지만 4로 나누어 떨어지고 100으로 나누어 떨어지면 평년입니다.<br>100으로도 나누어 떨어지지만 400으로도 나누어 떨어지면 윤년입니다.<br>이외의 나머지 연도는 모두 평년입니다.</p>
</blockquote>
<ol>
<li>연도를 입력 받고 윤년인지 아닌지 출력하시오<pre><code class="language-py">year = int(input(&quot;연도 입력 : &quot;))
</code></pre>
</li>
</ol>
<p>if year % 400 == 0:
    print(year, &quot;: 윤년입니다.&quot;)
elif year % 100 == 0:
    print(year, &quot;: 평년입니다.&quot;)
elif year % 4 == 0:
    print(year, &quot;: 윤년입니다.&quot;)
else :
    print(year, &quot;: 평년입니다.&quot;)</p>
<pre><code>* if, elif, else 문을 실행할 때 앞의 조건이 성립되면 나머지 구문은 실행하지 않는 다는 사실을 잘 생각해야한다.
* 예를 들어, `if year % 4 == 0:` 이 구문이 먼저 작성됐다면 4로 나누어 떨어지면서 100으로도 나누어 떨어지는 평년 역시 윤년으로 출력될 것이다.

2. 입력한 연도까지 윤년을 골라 출력하시오.

```py
year = int(input(&quot;연도 입력 : &quot;))
li = []

for i in range(1, year+1):
    if i % 400 == 0:
        li.append(i)
    elif i % 100 == 0:
        pass
    elif i % 4 == 0:
        li.append(i)
    else:
        pass

print(&quot;윤년 :&quot;, li)
</code></pre><ul>
<li><code>list.append()</code>를 활용하여 최종 윤년을 보기 쉽게 리스트로 출력하였다.</li>
</ul>
<h3 id="완전수"><strong>완전수</strong></h3>
<blockquote>
<p>완전수는 자기 자신을 제외한 양의 약수를 더했을 때 자기 자신이 되는 정수를 말합니다.<br>최초 다섯 개의 완전수는 6, 28, 496, 8128, 33550336</p>
</blockquote>
<ol>
<li>수를 입력받고 완전수인지 판단하는 프로그램</li>
</ol>
<pre><code class="language-py">N = int(input(&quot;수 입력 : &quot;))
li = []

for i in range(1, N):
    if N % i == 0:
        li.append(i)
if sum(li) == N:
    print(N,&quot;: 완전수&quot;)</code></pre>
<ul>
<li><code>for i in range(1, N):</code>, N+1이 아니라 N까지 해주는 이유는 완전수를 계산할 때 자기자신은 제외하기 때문이다.</li>
</ul>
<ol start="2">
<li>1부터 N까지 완전수를 출력하는 프로그램</li>
</ol>
<pre><code class="language-py">N = int(input(&quot;수 입력 : &quot;))

for i in range(1, N+1):
    li = []
    for j in range(1, i):
        if i % j == 0:
            li.append(j)
    if sum(li) == i:
        print(i, &quot;: 완전수&quot;)</code></pre>
<h3 id="소수"><strong>소수</strong></h3>
<blockquote>
<p>소수는 약수의 개수가 2개 즉, 1과 자기자신만을 약수로 가지고 있는 수를 말합니다.</p>
</blockquote>
<ol>
<li>N을 입력받고 N이 소수인지 판별하는 프로그램</li>
</ol>
<pre><code class="language-py">N = int(input(&quot;수 입력 : &quot;))
count = 0

for i in range(1, N+1):
    if N % i == 0:
        count += 1

if count == 2:
    print(N,&quot;은 소수입니다.&quot;)</code></pre>
<ol start="2">
<li>3 ~ N 까지 소수를 출력하는 프로그램</li>
</ol>
<pre><code class="language-py">N = int(input(&quot;수 입력 : &quot;))

for i in range(1, N+1):
    li = []
    for j in range(1, i+1):
        if i % j == 0:
            li.append(j)
    if len(li)==2:
        print(i, &quot;: 소수&quot;)</code></pre>
<ul>
<li><code>len(li)</code>를 통해 리스트의 길이 즉, 리스트 요소의 개수가 2인 수를 찾아서 출력한다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python for]]></title>
            <link>https://velog.io/@zinc_96/Python-study-04</link>
            <guid>https://velog.io/@zinc_96/Python-study-04</guid>
            <pubDate>Tue, 27 Jul 2021 04:41:22 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="4일차">4일차</h2>
<h3 id="for문"><strong>for문</strong></h3>
<blockquote>
<p>반복문 : for문 예제</p>
</blockquote>
<ol>
<li>1~99의 짝수를 모두 출력하는 프로그램을 작성하세요.</li>
</ol>
<pre><code class="language-py"># first
for i in range(1, 100):
    if i % 2 == 0:
        print(i)

# second
for i in range(2, 100, 2):
    print(i)</code></pre>
<ul>
<li>첫번째 방법은 2로 나눴을 때 나머지가 0인 수는 짝수라는 성질을 활용해서 구문을 작성한 것이다.</li>
<li>두번째 방법은 <code>range({1}, {2}, {3})</code>일때 <code>{3}</code>가 반복되는 간격이기에 짝수, 홀수의 간격이 2가 차이나기에 위와같이 작성할 수 있다.</li>
</ul>
<ol start="2">
<li>1에서 사용자가 입력한 수까지 짝수만 출력하는 프로그램<pre><code class="language-py">num = int(input(&quot;수 입력 : &quot;))
</code></pre>
</li>
</ol>
<p>for i in range(2, num+1, 2):
    print(i)</p>
<pre><code>* 여기서 주의할 점은 `range(first_num, final_num)`를 봤을때 `final_num + 1`을 해줘야지만 반복이 `final_num`까지 진행된다는 것이다. 

3. 1에서 10까지의 합을 구하여라
```py
sum = 0
for i in range(1, 11):
    sum += i

print(sum)</code></pre><ol start="4">
<li>단을 입력받고, 해당 단을 출력하는 프로그램(구구단)</li>
</ol>
<pre><code class="language-py">user = int(input(&quot;몇 단? : &quot;))

for i in range(1,10):
    print(user,&quot;x&quot;,i,&quot;=&quot;,user*i)</code></pre>
<ul>
<li>반복되는 부분이 어느 부분인지 잘 생각하면서 진행해야 한다.</li>
</ul>
<ol start="5">
<li>사용자에게 정수를 입력받고, 약수들을 출력해주는 프로그램<pre><code class="language-py">user = int(input(&quot;정수 입력 : &quot;))
li = []
</code></pre>
</li>
</ol>
<p>for i in range(1, user+1):
    if user % i == 0:
        li.append(i)</p>
<p>print(li)</p>
<pre><code>* 반복문을 통해서 프린트 정수의 약수를 프린트 해도 되지만
* list의 append를 활용하여 반복적으로 요소를 추가시킨 후 출력해도 된다.

6. 1부터 100까지의 홀수의 합을 구하는 프로그램
```py
sum = 0

for i in range(1, 100, 2):
    sum += i

print(sum)</code></pre><blockquote>
<p><strong>if</strong>문을 활용해준다면 <strong>for</strong>문 내부에<br><code>if i % 2 == 1:</code>이런식으로 작성하면 된다.</p>
</blockquote>
<ol start="7">
<li>factorial을 구하는 프로그램<pre><code class="language-py">su = int(input(&quot;수 입력 : &quot;))
</code></pre>
</li>
</ol>
<p>x = 1</p>
<p>for i in range(1, su+1):
    x *= i</p>
<p>print(x)</p>
<pre><code>* 5 factorial : 5! = 5x4x3x2x1
* 반복문을 이용해서 계속해서 곱을 수행해주면 된다.

### **for문의 중첩**

8. N을 입력받고, 2에서 N까지 수의 약수의 개수를 출력해라


```py
N = int(input(&quot;입력 : &quot;))

for i in range(2, N+1):
    count = 0
    for j in range(1, i+1):
        if i % j == 0:
            count += 1

    print(i,&quot;의 약수의 개수 : &quot;, count)</code></pre><ul>
<li>2에서 N까지의 수의 반복과 약수의 개수를 출력해주는 반복을 잘 구별해서 생각해야한다.</li>
<li>약수의 개수를 출력하는 것이기 때문에 count 변수를 지정한 후에 반복되는 수 만큼 <code>count += 1</code>을 해준다.</li>
</ul>
<ol start="9">
<li>2단부터 9단까지 출력해주는 프로그램을 작성하세요.<pre><code class="language-py">for i in range(2, 10):
 print(i, &quot;단&quot;)
 for j in range(1, 10):
     print(i,&quot;x&quot;,j,&quot;=&quot;,i*j)
 print()
</code></pre>
</li>
</ol>
<pre><code>
10. N을 입력받고, 2에서 N까지 수의 약수를 출력해라
```py
N = int(input(&quot;입력 : &quot;))

for i in range(2, N+1):
    print(i, &quot;의 약수는 : &quot;, end=&#39;&#39;)
    for j in range(1, i+1):
        if i % j == 0:
            print(j, end=&#39; &#39;)
    print()</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[Python list, tuple]]></title>
            <link>https://velog.io/@zinc_96/Python-study-3</link>
            <guid>https://velog.io/@zinc_96/Python-study-3</guid>
            <pubDate>Thu, 22 Jul 2021 05:31:32 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="3일차"><strong>3일차</strong></h2>
<blockquote>
<p>순서있는 자료형, 반복문</p>
</blockquote>
<h3 id="list-tuple"><strong>List, Tuple</strong></h3>
<blockquote>
<p>순서가 있는 자료형 : 리스트와 튜플</p>
</blockquote>
<ul>
<li>리스트는 <code>[</code>를 사용해서 나타내고, 튜플은 <code>(</code>를 사용해서 나타낸다.</li>
</ul>
<pre><code class="language-py">A = [1, 2, &#39;hello&#39;, &quot;world&quot;, True]  
B = (4, False, &#39;a&#39;, &quot;b&quot;, 4.3)

print(type(A))    # class &#39;list&#39; 확인
print(type(B))    # class &#39;tuple&#39; 확인</code></pre>
<ul>
<li>위처럼 묶어놓은 자료들에게는 각각의 번호가 주어지며 이러한 번호를 <strong>index(인덱스)</strong> 라고 한다.</li>
<li>인덱스는 0부터 시작한다.</li>
<li>각각의 자료에 접근하는 방법은 <strong>리스트,튜플이름[index]</strong>이다.</li>
</ul>
<pre><code class="language-py">A = [1, 2, &#39;hello&#39;, &quot;world&quot;, True]  
B = (4, False, &#39;a&#39;, &quot;b&quot;, 4.3)

print(A[0], A[2], A[4])
print(B[1], B[3])</code></pre>
<blockquote>
<p>리스트와 튜플의 차이점 : 자료 변경이 가능한가?</p>
</blockquote>
<ul>
<li>리스트는 자료를 변경할 수 있고 튜플은 자료 변경이 불가능하다. </li>
<li>만약 튜플의 자료를 변경하고 싶다면 형변환을 통해 실행해줘야한다.</li>
</ul>
<pre><code class="language-py">B = (4, False, &#39;a&#39;, &quot;b&quot;, 4.3)
print(&#39;변경 전 :&#39;,B)
B = list(B)
B[1] = 3
B = tuple(B)
print(&#39;변경 후 :&#39;,B)</code></pre>
<h3 id="list"><strong>List</strong></h3>
<hr>
<blockquote>
<p>list 의 특징</p>
</blockquote>
<table>
<thead>
<tr>
<th align="center">표현형</th>
<th align="center">뜻</th>
</tr>
</thead>
<tbody><tr>
<td align="center">len(list)</td>
<td align="center">요소의 개수</td>
</tr>
<tr>
<td align="center">list.appent(&quot;요소&quot;)</td>
<td align="center">요소 추가(끝)</td>
</tr>
<tr>
<td align="center">list.insert(위치, 요소)</td>
<td align="center">요소 추가(위치 지정)</td>
</tr>
<tr>
<td align="center">list.pop()</td>
<td align="center">요소 삭제(반환)</td>
</tr>
<tr>
<td align="center"><code>A=li.pop()</code></td>
<td align="center">요소를 반환해서 A에 대입</td>
</tr>
<tr>
<td align="center">list.count(요소)</td>
<td align="center">리스트 내 요소 개수 반환</td>
</tr>
</tbody></table>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python if]]></title>
            <link>https://velog.io/@zinc_96/Python-study-2</link>
            <guid>https://velog.io/@zinc_96/Python-study-2</guid>
            <pubDate>Wed, 21 Jul 2021 01:24:08 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="2일차">2일차</h2>
<blockquote>
<p>제어문 if, bool, 비교연산, 논리연산</p>
</blockquote>
<ol>
<li>수를 입력받고, 해당 수가 짝수인지 아닌지 판별하는 프로그램을 작성하세요.</li>
</ol>
<ul>
<li>짝수 판별 프로그램<pre><code class="language-py">num = int(input(&quot;수 입력 : &quot;))
</code></pre>
</li>
</ul>
<p>if num % 2 :
    print(&quot;홀수&quot;)
else : 
    print(&quot;짝수&quot;)</p>
<pre><code>* `%` 나머지 연산을 적절하게 활용해줘야 한다.
* `if num%2 == 0`으로 해줘도 되지만 `bool`함수의 특징을 살려 위처럼 해줘도 된다.
* `num % 2`가 1인경우 `1 = True`이기에 if의 종속문장이 실행된다.
* `num % 2`가 0인경우 `0 = False`이기에 else의 종속문장이 실행되는 것이다.

2. 두 수를 입력받고(0~99), 두 수를 더할 때 받아올림이 발생하는지 하지 않는지 알아보는 프로그램을 작성하세요.
* 받아올림 판별 프로그램
```py
a = int(input(&quot;수 : &quot;))
b = int(input(&quot;수 : &quot;))

a_tail = a%10
b_tail = b%10

if a_tail + b_tail &gt;= 10:
    print(&quot;받아올림 발생&quot;)
else :
    print(&quot;받아올림 미발생&quot;)</code></pre><ul>
<li><code>%</code> 나머지 연산을 적절하게 활용해줘야 한다.</li>
<li><code>a_tail, b_tail</code>처럼 각 수의 1의 자리 수를 비교해가며 연산을 진행하면 된다.</li>
</ul>
<ol start="3">
<li>A를 입력받고, A 가 10보다 작은 짝수인지 판별하는 프로그램을 작성하세요.</li>
</ol>
<ul>
<li>if 중첨<pre><code class="language-py">A = int(input(&quot;수 입력 : &quot;))
</code></pre>
</li>
</ul>
<h1 id="1번">1번</h1>
<p>if A &lt; 10 :
    if A % 2 == 0:
        print(&quot;짝수입니다&quot;)
    print(&quot;10보다 작다.&quot;)</p>
<p>#2번
A = int(input(&quot;수 입력 : &quot;))
if A &lt; 10 and A % 2 == 0:
    print(&quot;10 보다 작은 짝수&quot;)</p>
<pre><code>* if 구문 내부에 if문을 사용해줌으로써 if의 중첩 구문을 작성할 수 있다.
* 1번처럼 중첩해서 사용해줄 수도 있지만 2번과 같이 조건을 `and`나 `or`연산을 넣어서 한번에 처리해 주는 구문도 존재한다.

4. 두 수를 입력받고(0-99), 큰 수에서 작은 수를 뺏을 때 받아내림이 발생하는지 판별하는 프로그램을 작성하세요.
* 받아내림 판별 프로그램
```py
num1 = int(input(&quot;수 : &quot;))
num2 = int(input(&quot;수 : &quot;))

num1_t = num1%10
num2_t = num2%10

if (num1 &gt; num2):
    if num1_t - num2_t &lt; 0:
        print(&quot;받아내림 발생&quot;)
    else :
        print(&quot;받아내림 미발생&quot;)
elif (num1 &lt; num2):
    if num2_t - num1_t &lt; 0:
        print(&quot;받아내림 발생&quot;)
    else :
        print(&quot;받아내림 미발생&quot;)</code></pre><ul>
<li><code>num1_t</code>와 같이 각 수의 1의 자리 수를 비교해가면서 연산하면 답을 구할 수 있다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python 입출력]]></title>
            <link>https://velog.io/@zinc_96/Python-study-1</link>
            <guid>https://velog.io/@zinc_96/Python-study-1</guid>
            <pubDate>Tue, 20 Jul 2021 11:51:13 GMT</pubDate>
            <description><![CDATA[<h1 id="python-study"><strong>Python study</strong></h1>
<h2 id="1일차"><strong>1일차</strong></h2>
<blockquote>
<p>print, 변수, type, input, 연산</p>
</blockquote>
<h3 id="1-시간-분-초를-입력받고-해당-시간이-몇초인지-출력하는-프로그램을-작성하세요">1. 시간, 분, 초를 입력받고 해당 시간이 몇초인지 출력하는 프로그램을 작성하세요.</h3>
<pre><code class="language-py">hour = int(input(&quot;몇 시간? &quot;))
mins = int(input(&quot;몇 분? &quot;))
sec = int(input(&quot;몇 초? &quot;))

time = hour*3600 + mins*60 + sec
# hour*(60**2) -&gt; 제곱 연산을 사용해줘도 됨

print(time)</code></pre>
<ul>
<li><code>input()</code>으로는 문자열로 받아지기 때문에 <code>int(input())</code>과 같이 형변환을 진행해줘야 한다.</li>
</ul>
<h3 id="2-국어-수학-과학-점수를-받고-평균을-구하는-프로그램을-작성하세요">2. 국어, 수학, 과학 점수를 받고 평균을 구하는 프로그램을 작성하세요.</h3>
<pre><code class="language-py">kor = int(input(&quot;국어 점수 : &quot;))
math = int(input(&quot;수학 점수 : &quot;))
sci = int(input(&quot;과학 점수 : &quot;))

avg = (kor + math + sci) / 3

print(&quot;평균 = &quot;, avg)</code></pre>
<ul>
<li>변수와 출력값을 함께 작성하고 싶을 때 <code>print(&quot;a&quot;,a)</code> 라고 입력해주면 이어서 출력</li>
</ul>
<h3 id="3-초를-입력받고-해당-초가-몇-시간-몇-분-몇-초인지-출력하는-프로그램을-작성하세요">3. 초를 입력받고, 해당 초가 몇 시간, 몇 분, 몇 초인지 출력하는 프로그램을 작성하세요.</h3>
<pre><code class="language-py">secs = int(input(&quot;초 입력 : &quot;))

hour = secs//3600
mins = secs%3600//60
sec = secs % 60

print(secs, &quot;초 = &quot;, hour, &quot;시간 &quot;, mins, &quot;분 &quot;, sec, &quot;초&quot;)</code></pre>
<ul>
<li>계산을 바로바로 하면서 확인하고 싶을때는 IDLE창을 열고 확인해가면서 진행해주면 좋다.</li>
<li>나눗셈을 통해 몫과 나머지를 적절히 활용하면 시간, 분, 초를 구할 수 있다.</li>
</ul>
<h3 id="4-생년월일을-입력받고-현재-나이를-출력하는-프로그램을-작성하세요">4. 생년월일을 입력받고, 현재 나이를 출력하는 프로그램을 작성하세요.</h3>
<p> ex) 생년월일 : 19930813<br>    현재나이는 29 입니다.</p>
<pre><code class="language-py">birth = int(input(&quot;생년월일 : &quot;))

age = 2021 - birth//10000 + 1
print(&quot;현재 나이는 : &quot;, age)</code></pre>
]]></description>
        </item>
    </channel>
</rss>