-2

I've been creating a two-player random number generator based guessing game and I made it so that the players can choose how many points they need to win. I can't seem to remember how to check whether an int variable is divisible by a certain number, as I am trying to use this to determine if the points total is a valid number. This is the section of code I'm looking at right now:

  if winpoint/5 != 0:
    blah = "Win points must be a multiple of 5. Try again.\n"
    for l in blah:
      sys.stdout.write(l)
      sys.stdout.flush()
      t.sleep(0.015)
    t.sleep(0.5)
    pointsdec()

pointsdec is the name of the function this is in by the way

I meant for this section of code to happen only when winpoint is a multiple of 5, i.e: 30, but this piece of code triggers regardless of what the user types. Can someone help me please??

1 Answers1

0

Use % instead of /. winpoint / 5 will only be zero if winpoint (or its absolute value) is less than 5. winpoint % 5 is only zero if (the absolute value of) pinpoint is divisible by 5 (otherwise, there would be a non-zero remainder).

chepner
  • 497,756
  • 71
  • 530
  • 681