mardi 23 mars 2021

Python if logic data not able to capture

Trying to capture the output stats, code below where I check for the Boolean condition. if true add to the body else pass or don't add any detail to the contain. Below logic work if final condition is true else nothing is captured within the contain. please advise how to achieve the contain based on different Boolean condition

fail = True
success = True
count = False

contain = ''
contain = contain + "\nFailed\n" if fail else ''
contain = contain + "\nSuccess\n" if success else ''
contain = contain + "\nCount\n" if count else ''

print(contain)

expected output

Failed

Success

current output is blank

However, if I change count variable to true, I'm able to achieve the expected output. But variable value are not always true. Need to capture only true condition


Aucun commentaire:

Enregistrer un commentaire