0
answer = 5
guess = input("guess number between 1 and 10:  ")

if guess == answer:
    print('great job!')

elif guess != answer:
    print('sorry')

else:
    print('wrong')
Peter O.
  • 32,158
  • 14
  • 82
  • 96
jmk93
  • 1
  • 1
    It prints 'great job!' for me. the answer is 5 if the input is 5 it prints 'great job' else it will print 'sorry' – yoav Nov 09 '19 at 17:00
  • Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Peter O. Nov 09 '19 at 17:01
  • Btw your `elseif` and `else` logically civer the same cass so one is redundant and should be removed. – Marcin Orlowski Nov 09 '19 at 17:18
  • when i enter 5 it is printing 'sorry instead of 'great job' – jmk93 Nov 09 '19 at 17:19
  • @MarcinOrlowski but still not printing the 'great' instead printing 'wrong' – jmk93 Nov 09 '19 at 17:21

1 Answers1

0

this is because of the object type.

here answer has object type of int while guess has object type of str, input function give object type of string, both are different.

to make it according to your need, you need to change the input object type.

so if you do guess = int(input()), your code will work accordingly

sahasrara62
  • 10,069
  • 3
  • 29
  • 44