0

I feel stupid for asking this question but I have no idea why this isn't working. It keeps showing incorrect for every time I run the program

import random
print("Pick a number 1-2")
ry = input()
nmr = random.randrange(0,2)
if ry == nmr:
    print('congrats')
else:
    print('Incorrect')
    
if ry not in '1,2':
    print('Invalid Input - * 1-2 Input requested* ')
  • 2
    Because `ry` is a `str` and `nmr` is an `int`. They'll never compare equal. Got to do something like `ry = int(input())` instead. – Random Davis Dec 15 '22 at 23:37
  • Thank You I keep forgetting that rule. –  Dec 15 '22 at 23:40
  • See: https://www.w3schools.com/python/trypython.asp?filename=demo_ref_random_randrange. `#returns a number between 3 (included) and 9 (not included) `. – MSH Dec 15 '22 at 23:40
  • 1
    @python it's not really a Python rule, it's standard for programming languages to not allow you to compare unrelated types to each other. The fact that you can do it in JavaScript is an exception, not the norm. And most devs hate that JS works that way. – Random Davis Dec 15 '22 at 23:55

0 Answers0