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 strings:
"both" if both given booleans a and b are True."first" if only a is True."second" if only b is True ."neither" if both a and b are False.If-else statements can be written as a oneliner using Python's ternary operator.
For example, the code:
def startswith(name):
if name[0] in "AEIOU":
return "vowel"
else:
return "consonant"
Can be simplified to:
def startswith(name):
return "vowel" if name[0] in "AEIOU" else "consonant"
You can concatenate as many ternary operators as you want. However, concatenating too many will definitely diminish the readability of your code.
"majority" if x > 50 else "minority" if x < 50 else "draw"