Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Majority by Khrystyna11
def is_majority(items: list[bool]) -> bool:
num_true = 0
num_false = 0
for i in items:
if i == True:
num_true += 1
else:
num_false += 1
if num_true > num_false:
return True
return False
print("Example:")
print(is_majority([True, True, False, True, False]))
# These "asserts" are used for self-checking
assert is_majority([True, True, False, True, False]) == True
assert is_majority([True, True, False]) == True
assert is_majority([True, True, False, False]) == False
assert is_majority([True, True, False, False, False]) == False
assert is_majority([False]) == False
assert is_majority([True]) == True
assert is_majority([]) == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
July 12, 2024
Comments: