<div><br></div> <div>코드카데미로 더듬더듬 파이썬 공부하고 있는 학생입니다.</div> <div><br></div> <div>파이썬의 리스트, 사전형 부분에서 막혀 질문드립니다.</div> <div><br></div> <div>예제가 슈퍼마켓의 품목별 가격과 재고 수량을 사전형으로 만든 뒤</div> <div>for문을 사용하여 품목별 가격과 재고를 출력하고</div> <div>또 각 가격과 재고를 곱한 값을 합해 슈퍼마켓의 품목을 모두 팔 경우 총 수입을 구하는 문제인데요</div> <div>제가 막힌 부분은 마켓의 총 수입을 구하는 부분입니다.</div> <div><br></div> <div> <div>prices = {</div> <div> "banana" : 4,</div> <div> "apple" : 2,</div> <div> "orange" : 1.5,</div> <div> "pear" : 3,</div> <div>}</div> <div>stock = {</div> <div> "banana" : 6,</div> <div> "apple" : 0,</div> <div> "orange" : 32,</div> <div> "pear" : 15,</div> <div>}</div> <div><br></div> <div>for key in prices:</div> <div> print key</div> <div> print "price: %s" % prices[key]</div> <div> print "stock: %s" % stock[key]</div></div> <div><br></div> <div>여기까지가 지금 진행한 부분이고 문제에 대한 설명은</div> <div>아래와 같습니다. 어떤 명령어를 사용하라는 지시도 없고 막혀서 끙끙거리고 있습니다.</div> <div>도움 부탁드립니다ㅠ</div> <div> <p style="margin:0px 0px 18px;font-family:'Open Sans', 'Hevetica Neue', Helvetica, sans-serif;font-size:15px;line-height:22px;color:#333333;background-color:#f0faff;">Let's determine how much money you would make if you sold all of your food.</p> <p style="margin:0px 0px 18px;font-family:'Open Sans', 'Hevetica Neue', Helvetica, sans-serif;font-size:15px;line-height:22px;color:#333333;background-color:#f0faff;"><span style="line-height:20px;">Create a variable called</span><span style="line-height:20px;"> </span><code class="undefined" style="line-height:inherit;padding:.15em .25em;font-size:.85em;border:1px solid;font-family:Monaco, Menlo, 'Ubuntu Mono', Consolas, 'source-code-pro', monospace;">total</code><span style="line-height:20px;"> </span><span style="line-height:20px;">and set it to zero.</span></p> <p style="margin:0px 0px 18px;font-family:'Open Sans', 'Hevetica Neue', Helvetica, sans-serif;font-size:15px;line-height:22px;color:#333333;background-color:#f0faff;"><span style="line-height:20px;">Loop through the</span><span style="line-height:20px;"> </span><code class="undefined" style="line-height:inherit;padding:.15em .25em;font-size:.85em;border:1px solid;font-family:Monaco, Menlo, 'Ubuntu Mono', Consolas, 'source-code-pro', monospace;">prices</code><span style="line-height:20px;"> </span><span style="line-height:20px;">dictionaries.</span></p> <ol style="padding:0px;margin:0px 0px 18px;list-style:none;color:#333333;font-family:'Open Sans', 'Hevetica Neue', Helvetica, sans-serif;font-size:15px;line-height:22px;background-color:#f0faff;"><li style="line-height:20px;margin-top:9px;margin-bottom:9px;">For each key in <code class="undefined" style="padding:.15em .25em;font-size:.85em;line-height:inherit;border:1px solid;font-family:Monaco, Menlo, 'Ubuntu Mono', Consolas, 'source-code-pro', monospace;">prices</code>, multiply the number in <code class="undefined" style="padding:.15em .25em;font-size:.85em;line-height:inherit;border:1px solid;font-family:Monaco, Menlo, 'Ubuntu Mono', Consolas, 'source-code-pro', monospace;">prices</code> by the number in <code class="undefined" style="padding:.15em .25em;font-size:.85em;line-height:inherit;border:1px solid;font-family:Monaco, Menlo, 'Ubuntu Mono', Consolas, 'source-code-pro', monospace;">stock</code>. Print that value into the console and then add it to <code class="undefined" style="padding:.15em .25em;font-size:.85em;line-height:inherit;border:1px solid;font-family:Monaco, Menlo, 'Ubuntu Mono', Consolas, 'source-code-pro', monospace;">total</code>.</li> <li style="line-height:20px;margin-top:9px;margin-bottom:9px;">Finally, outside your loop, <code class="python" style="padding:.15em .25em;font-size:.85em;line-height:inherit;border:1px solid;font-family:Monaco, Menlo, 'Ubuntu Mono', Consolas, 'source-code-pro', monospace;"><span class="keyword">print</span> total</code>.</li></ol></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.