Check the principles of minimalist code in the [intro to the first challenge] (https://innokodakademija.com/challenge/2XLjgZhmACph76Pkr).
In the Code tab you will find a code that is missing a single character in order to pass the tests. However, your goal is to submit a function as minimalist as possible. Use the tips in the tips section below.
Write a function that returns the boolean True if the given number is zero, the string "positive" if the number is greater than zero or the string "negative" if it's smaller than zero.
Executing a return will effectively end your function.
For example, the code:
def compare_to_100(x):
if x > 100:
return "greater"
elif x < 100:
return "smaller"
else:
return "equal"
Can be simplified to:
def compare_to_100(x):
if x > 100:
return "greater"
if x < 100:
return "smaller"
return "equal"
x is greater than 100, Python will not execute the code past the first return.x is smaller than 100, Python will not execute the code inside the first if statement or past the second return.x is equal to 100, Python will not execute the code inside the two if statements.return inside your if statement.Further simplification of the code above:
def compare_to_100(x):
return "greater" if x > 100 else "smaller" if x < 100 else "equal"