LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-20-2004, 09:57 PM   #1
tearinox
Member
 
Registered: Aug 2003
Location: you dont want to know
Distribution: Gentoo 2004.2, Slackware 10, Windows XP, Windows 2003 Server
Posts: 348

Rep: Reputation: 30
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?
 
Old 08-20-2004, 10:04 PM   #2
DanTheKiwi
LQ Newbie
 
Registered: Aug 2004
Location: Sydney, Australia
Distribution: FreeBSD, Fedora Core 2
Posts: 20

Rep: Reputation: 0
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!
 
Old 08-20-2004, 10:07 PM   #3
DanTheKiwi
LQ Newbie
 
Registered: Aug 2004
Location: Sydney, Australia
Distribution: FreeBSD, Fedora Core 2
Posts: 20

Rep: Reputation: 0
http://honors.montana.edu/~jjc/easyt...00000000000000

I found this link to satisfy my curiosity

Hope it helps!
 
Old 08-20-2004, 10:09 PM   #4
tearinox
Member
 
Registered: Aug 2003
Location: you dont want to know
Distribution: Gentoo 2004.2, Slackware 10, Windows XP, Windows 2003 Server
Posts: 348

Original Poster
Rep: Reputation: 30
aha! thats it.. genius!
lol.. alright cool, glad i got that figured out. Thanks
 
Old 08-20-2004, 10:12 PM   #5
DanTheKiwi
LQ Newbie
 
Registered: Aug 2004
Location: Sydney, Australia
Distribution: FreeBSD, Fedora Core 2
Posts: 20

Rep: Reputation: 0
Any time mate
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate random number with C++ TruongAn Programming 5 11-09-2005 12:01 AM
random number generation sailu_mvn Programming 4 03-10-2005 02:10 PM
Random number generators blufire Programming 5 11-09-2004 06:02 PM
Python Random number sethgeekx86 Programming 4 06-10-2004 08:55 AM
I need random number in C ... purpleburple Programming 4 10-28-2002 04:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration