-1

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?

Marshall
  • 15
  • 5

1 Answers1

3

Think about what is the actual condition for printing. If only one of them may be true and the other one not, then what can you figure? Look at the piece of code below and observe that the two conditions may not be equal to each other, simple as that!

cond1 = pricelist[-1] == ("$0.00")
cond2 = pricelist[-2] != pricelist[-1]

if(cond1 != cond2):
    print(pricelist)
Anteino
  • 1,044
  • 7
  • 28