1

I'm currently hosting an online scavenger hunt game, and one of the steps involves "unrolling" bales of hay to find a clue. For some reason, whenever I test it, any number is counted as correct.

import random
import time
bale = int(input("Say a number 1-250 to unroll a bale of hay! It will take 45 seconds before you're told if clues are inside of it, so be willing to wait.")
if int(bale) == 63 or 190 or 36 or 106 or 127 or 89 or 84 or 44 or 80 or 124 or 173 or 202 or 224 or 51 or 220:
  print "Wait 45 seconds to unroll the bale."
  time.sleep(15)
  print "30 seconds left..."
  time.sleep(5)
  print "..."
  time.sleep(5)
  print "20 seconds left..."
  time.sleep(10)
  print "10 seconds..."
  time.sleep(5)
  print "5 seconds..."
  time.sleep(1)
  print "4!"
  time.sleep(1)
  print "3!"
  time.sleep(1)
  print "2!"
  time.sleep(1)
  print "1!"
  time.sleep(1)
  print "Yes! There's a clue in here! Send a screenshot of this for confirmation to move on!"
else:
  print "Wait 45 seconds to unroll the bale."
  time.sleep(15)
  print "30 seconds left..."
  time.sleep(5)
  print "..."
  time.sleep(5)
  print "20 seconds left..."
  time.sleep(10)
  print "10 seconds..."
  time.sleep(5)
  print "5 seconds..."
  time.sleep(1)
  print "4!"
  time.sleep(1)
  print "3!"
  time.sleep(1)
  print "2!"
  time.sleep(1)
  print "1!"
  time.sleep(1)
  print "Sorry, no clue. Refresh the page and try again with a new number."
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
pikachad
  • 11
  • 1

1 Answers1

0

When you write an or clause, each argument is evaluated as a boolean. So really what you've written is interpreted as:

Is int(bale) == 63 true? Or is 190 true? Or is 36 true? Etc.

Python is converting these integers to bool values and evaluating if they are true. Note that bool(n) is false for all integers, n, except n = 0, so this results in the condition in the if always being true.

What you are looking to do is to check if int(bale) is equal to any of the integers. This can be accomplished by changing the check to:

if int(bale) == 63 or int(bale) == 190 or int(bale) == 36 or...

A more readable and fast approach would be to use a set:

if int(bale) in {63, 190, 36, ...}:
shayaan
  • 1,482
  • 1
  • 15
  • 32
  • thanks for the help! sorry i came here with such a simple question, i knew what was wrong just not how to fix it, tysm! – pikachad Feb 13 '21 at 13:54
  • @pikachad no worries, appreciate it if you can vote for/mark the answer as correct! – shayaan Feb 13 '21 at 21:37