0

This is supposed to be a random number guessing game. It is supposed to say whether the number was guessed correctly or not at the end but it will always display "Wrong" even if the number has been guessed correctly.

I've only been learning python for a couple of days and this is doing my head in.

import random

odds = [1,2]
rNum=(random.choice(odds))

print ('The odds are:',odds)
gNum=input('What is your guess?')

print ('You Guessed:',gNum)
print ('The number was:',rNum)

if (rNum == gNum):
   (print("Correct!"))
if (rNum != gNum):
   (print("Wrong"))

Its as if it can't compare if the number is the same or not and always interprets it as wrong, as it only will give the != result

Forgive me if I sound foolish I am only beginning

Many thanks :)

Hashki
  • 1
  • 1

1 Answers1

1

I imagine the types are different. One is an int, the other a str which happens to contain an integer. Try"

gNum=int(input('What is your guess?'))
brunns
  • 2,689
  • 1
  • 13
  • 24