-6

Results I get for this code is true but the results are false.Checked in atom code editor and online editor

a = "https://www.reddit.com/comments/ado0ym/use_reddit_coins_to_award_gold_to_your_favorite/"
b = "aaaaaaa"
c = "somthing random"

if b or c in a:
    print("true")

else:
    print("false")


# Results return True
am guru prasath
  • 345
  • 1
  • 7
  • 28

2 Answers2

4

Python doesnt run this code correctly

 if b or c in a:
    print("true")

The reason is that python percieves this as

 if (b) or (c in a):

And as if b is always True so code doesnt work as expected

This should be

 if (b in a) or (c in a):
    print("true")

Hope it helps

Talha Israr
  • 654
  • 6
  • 17
0

The problem with your code is the following:

if b or c in a:
    print("true")

This first checks if b exists. which it does. So it gives True.

What you should do is:

if (b in a) or (c in a):
Stef van der Zon
  • 633
  • 4
  • 13