You’re Decent At Python If You Can Find These 4 Mistakes
<h1>How this works</h1>
<ul>
<li>There’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’t find the mistakes in these 4 functions, this doesn’t mean that you’re not decent at Python.</p>
<blockquote>
<p>It just means you’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):
'''
input: ['apple', 'orange', 'apple']
output: {'apple':2, 'orange':1}
'''
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’s a function that takes in an integer, and returns <code>True</code> if the input integer is a prime number, and <code>False</code> 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>