0

I've been working on a small project to help my coding, and have run into a simple problem, So I'm trying to recreate a small game calls 'odds on' as per where I live, where you and a friend say a number, let's say between 1 and 5, at the same time, and if your friend says the same number as you, you win, basically, and I've got my code working, mostly, however it only says that I lose, even if the computer answer is equal to my answer, have a look at the whole code:

oddsonplayer = input("")

print(oddsonplayer)

import random
oddsoncomputer = (random.randint(1,5))

if oddsonplayer > "5":
    print("Pick a number between 1 and 5!")
if oddsonplayer == oddsoncomputer:
    print("You Win!")
else:
print("You Lose!")

So long story short, it says I lose, even if both numbers are equal.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
James.bvn
  • 3
  • 2

1 Answers1

0

Your code is correct. Just that you have a string, not a number. Convert the string to a number like this int(oddsonplayer)

oddsonplayer = input("")

print(oddsonplayer)

import random
oddsoncomputer = (random.randint(1,5))

if oddsonplayer > "5":
    print("Pick a number between 1 and 5!")
if int(oddsonplayer) == oddsoncomputer:
    print("You Win!")
else:
    print("You Lose!")
solidak
  • 5,033
  • 3
  • 31
  • 33