mercredi 11 décembre 2019

How to prevent Python script from printing even though conditions to print are True? [duplicate]

This question already has an answer here:

I want my Python script to print a list only if one condition is true between two separate conditions. However, it is possible for both conditions to be true at the same time. Below is the portion of code I am referring to:

pricelist = [main(), main()] #these list values are added from an earlier function in my script
i = 1
while i == 1:
    pricelist.append(main())
    pricelist.pop(0)
    if pricelist[-1] == ("$0.00"):
        pass #if the last append to pricelist is "$0.00" I don't want anything to print
    if pricelist[-2] != pricelist[-1]:
        print(pricelist)  # Print the contents of pricelist only if the 2 values are different but NOT print anything if the last append is "$0.00"

It is possible to have the list results be [‘some value’, ‘$0.00’]. In this case, even though both conditions I have listed in my script are true, I don’t want pricelist to print anything. What do I need to change in my script so pricelist won’t print if both conditions are true?

Aucun commentaire:

Enregistrer un commentaire