Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to assign the two different counts of something to a same variable?

I have the no. of A’s to count but in one of cell of an excel its ‘A’ & in some cells its ‘A ‘

So, If the cell has ‘A’ I want my code to count no of ‘A’ and store in count_a, else if my cell has ‘A ‘ I also want that to be counted and stored in same variable count_a.

def config(status: []) -> None:
    global count_a
    count_a = status.count('A' or 'A ')

This code somehow seems to be not working, Thanks for the help in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is not working because status.count('A' or 'A ') does not even close what you think it does. It does not count "A"s and "A "s. It counts "True"s, because first the expression 'A' or 'A ' is evaluated, which results in True and then count() counts.

You have to count them separately:

count_a = status.count('A')
count_a += status.count('A ')

or

count_a = status.count('A') + status.count('A ')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading