In this example, we will use the count method from the Python array list to decide which phrase to return from a function that will accept an array list consists of good and bad ideas.

In the below example, you need to decide which phrase to return from the array list which consists of good ideas ‘good’ and bad ideas ‘bad’. If there are one or two good ideas, return ‘Publish!’, if there are more than 2 return ‘I smell a series!’. If there are no good ideas, as is often the case, return ‘Fail!’.

def well(x):

    if x.count('good') > 2:

        return 'I smell a series!'
        
    elif x.count('good') > 0:

        return 'Publish!'

    else:

        return 'Fail!'

Write down your own python answer in below comment box.

If you like this post do share the post on any social media site to help this site to grow, thank you.

Click to rate this post!
[Total: 4 Average: 1]
Please follow and like us:
error0

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *