ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Gentoo 2004.2, Slackware 10, Windows XP, Windows 2003 Server
Posts: 348
Rep:
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?
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.