LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Random Number Game (https://www.linuxquestions.org/questions/programming-9/random-number-game-220384/)

tearinox 08-20-2004 09:57 PM

Random Number Game
 
Hey guys,
Working on some python and some guys in irc said i should write a random number game to practice my python skills.. What a piece of cake i thought, i wrote this in about 5 minutes:

Code:

import random
counter = 0

x = raw_input('Choose a number between 1 and 10: ')
y = random.randint(1,10)

if x == y:
        print "Your answer:", x, "Correct Answer:", y
        print "YOU WIN!"
else:
        print "Your answer:", x, "Correct Answer:", y
        print "YOU LOSE! ahahaha in your FACE!"

However, what I notice is that when I DO ACTUALLY WIN.. it still says i lost.

Code:

Choose a number between 1 and 10: 5
Your answer: 5 Correct Answer: 5
YOU LOSE! ahahaha in your FACE!

This is just so basic that I thought I'd better figure out what I'm doing wrong here, for when I program bigger size apps.
Any ideas why its producing this logical error?

DanTheKiwi 08-20-2004 10:04 PM

I don't know python so I'm not sure if I will be right or even on the right track, but could it possibly be because when you enter into the keyboard it sends a charactor not a number? Maybe you need to convert the input to an integer?

In C, the value of the 5 you type into your keyboard is actually 35 (i think! :P), as it is just 5, the charactor, not the number, unless you specifically look for an integer from input it will be taken as a charactor.. Maybe your problem is with this?

Like I said, i don't know python.. but just trying to help!

DanTheKiwi 08-20-2004 10:07 PM

http://honors.montana.edu/~jjc/easyt...00000000000000

I found this link to satisfy my curiosity :)

Hope it helps!

tearinox 08-20-2004 10:09 PM

aha! thats it.. genius!
lol.. alright cool, glad i got that figured out. Thanks

DanTheKiwi 08-20-2004 10:12 PM

Any time mate :)


All times are GMT -5. The time now is 09:11 AM.