0

It always turn out to print out "Sorry", even if the number is the same. Why doesn't this if statement work?

    import random

    high_number = input("What is the maximum number?\nExample(20): ")  
    print('0-{}'.format(high_number))  

    guess = input("Guess the number: ")  
    high_number = int(high_number)  

    value = random.randint(0, high_number)  

    if value != guess:  
       print("Sorry.")  
    elif value == guess:  
       print("Hurray!")  
Erik77
  • 109
  • 4
  • 12
  • `input()` returns a string and you are comparing `int value` to `String guess` which is always false. Change `value!=guess` to `value!=high_number` and it should work. – Mathews Mathai Apr 28 '18 at 18:34
  • Possible duplicate of [How can I read inputs as integers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers) – jwodder Apr 28 '18 at 18:39

1 Answers1

0

Issue: input() returns String and not int

input() returns a string and you are comparing int value to String guess which is always false. Change value!=guess to value!=high_number and it should work.

Use high_number which is the integer value of the String guess.

Mathews Mathai
  • 1,707
  • 13
  • 31