Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
Created June 3, 2020 12:29
Show Gist options
  • Save kurzweil777/7451734c6fb9ac64387cc4dcc26ac1e1 to your computer and use it in GitHub Desktop.
Save kurzweil777/7451734c6fb9ac64387cc4dcc26ac1e1 to your computer and use it in GitHub Desktop.
Exercise_from_CodeWars
def iq_test(numbers):
"""Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given
numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help
Bob — to check his answers, he needs a program that among the given numbers finds one that is different in
evenness, and return a position of this number. """
all_numbers: list = [] # Creating a list to save all odd and even values
odd_count: int = 0 # Creating an int to count an odd value
even_count: int = 0 # Creating an int to count an even value
for number in numbers.split(): # Checking if a number from a given list is an odd or even
if int(number) % 2 == 0:
all_numbers.append('Even')
else:
all_numbers.append('Odd')
for count in all_numbers: # Counting how many odds and evens we have
if count == 'Even':
even_count += 1
else:
odd_count += 1
if even_count > odd_count:
# Returning the position of an odd number if there are more even numbers
return all_numbers.index('Odd') + 1
else:
# Returning the position of an even number if there are more odd numbers
return all_numbers.index('Even') + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment