0

When I call my function in the Python shell I want the list of boolean arguments to be inside both regular parentheses and square brackets like so which_animal([True,True,True,True,True,True,True]) if someone can also explain the process used it would serve to be very helpful.

Here is my code for any reference

which_animal(backbone,shell,six_legs,give_birth_to_live_babies,feathers,gills,lay_eggs_in_water):

if backbone:
    if give_birth_to_live_babies:
        return 'Mammal'
    if feathers:
        return 'Bird'
    if gills:
        return 'Fish'
    if lay_eggs_in_water:
        return 'Amphibian'
    if not lay_eggs_in_water:
        return 'Reptile'

if not backbone:
    if shell:
        return 'Mollusc'
    if six_legs:
        return 'Insect'
    if not six_legs:
        return 'Arachnid'
sshashank124
  • 31,495
  • 9
  • 67
  • 76
MrWallace
  • 37
  • 7

1 Answers1

1

You can pass it by unpacking the boolean list using *. Here is how you would do it:

which_animal(*[True,True,True,True,True,True,True])

That way, you don't need to make any adjustments to your method.

DEMO

Alternatively, you could make your which_animal method accept a list but this code is really hard to understand by itself.

def which_animal(l):
    if l[0]:
        if l[3]:
            return 'Mammal'
        if l[4]:
            return 'Bird'
        if l[5]:
            return 'Fish'
        if l[6]:
            return 'Amphibian'
        if not l[6]:
            return 'Reptile'

    if not l[0]:
        if l[1]:
            return 'Mollusc'
        if l[2]:
            return 'Insect'
        if not l[2]:
            return 'Arachnid'

>>> print which_animal([True,True,True,True,True,True,True])
Mammal
sshashank124
  • 31,495
  • 9
  • 67
  • 76