You’re Decent At Python If You Can Find These 4 Mistakes

<h1>How this works</h1> <ul> <li>There&rsquo;ll be 4 Python functions, and each does something</li> <li>Each function has ONE wrong line</li> <li>You need to take steps to identify the ONE wrong line</li> <li>Try not to read the comments for clues</li> </ul> <p>If you can&rsquo;t find the mistakes in these 4 functions, this doesn&rsquo;t mean that you&rsquo;re not decent at Python.</p> <blockquote> <p>It just means you&rsquo;re not decent at Python YET.</p> </blockquote> <p>We all start from zero at some point, and you just need enough practice and consistency to go from being not decent to decent!</p> <h1>1) Counting Fruits</h1> <p>Given a list of fruits, the function counts the number of times each fruit appears, and returns a dictionary containing each fruit and its count.</p> <pre> def count_fruits(fruits): &#39;&#39;&#39; input: [&#39;apple&#39;, &#39;orange&#39;, &#39;apple&#39;] output: {&#39;apple&#39;:2, &#39;orange&#39;:1} &#39;&#39;&#39; out = {} for fruit in fruits: if fruit not in out: out[fruit] = 1 else: out[fruit] += 1 return out</pre> <h1>2) Checking for prime numbers</h1> <p>Here&rsquo;s a function that takes in an integer, and returns&nbsp;<code>True</code>&nbsp;if the input integer is a prime number, and&nbsp;<code>False</code>&nbsp;otherwise. A prime number is defined as an integer larger than 1 that can only be divided by 1 and itself.</p> <p><a href="https://levelup.gitconnected.com/youre-decent-at-python-if-you-can-find-these-4-mistakes-e02519d44995">Website</a></p>
Tags: Python Decent