May 25, 2012, 06:58:08 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Prowlie Welcome back! The site migration is complete and normal service resumed.
Advanced search
Pages: [1]   Go Down
Print
Author Topic: The Mathalator 3000! (Python)  (Read 1741 times)
0 Members and 2 Guests are viewing this topic.
Creepy Doll
Full Member
***
Offline Offline

Gender: Male
Posts: 121

In a town in the woods at the top of a hill...


« on: September 28, 2008, 02:20:53 PM »

Here's a little math program I put together in Python.
I just started learning about programming in general a few days ago so I'm quite proud of this little program.

Code:
#The Mathalator 3000
#Author: Steingrimur Jonsson
#Date: 28. 09. 2008


from random import randint

scoreCount = 0
qCount = 0
nOfQs = 0
frust = 0

print "Welcome to the mathalator 3000!\n"
print "How many questions would you like?\n(only up to 50)\n"
while nOfQs == 0 or nOfQs < 0 or nOfQs > 50:
    nOfQs = int(raw_input(""))
    print ""
    if nOfQs > (50 or nOfQs < 0) and frust >= 6:
        print "Alright, that's it! Get out!"
        exit()
    elif nOfQs > (50 or nOfQs < 0) and frust >= 3:
        frust += 1
        print "You're really starting to get on my nerves. Just pick a valid number."
    elif nOfQs > 50 or nOfQs < 0:
        frust += 1
        print "I'm afraid I can't let you do that. Please pick another number.\n"
    else:
        print "Alrighty, let's get this started.\n"


while qCount < nOfQs:
    rand = randint(1,3)
    if rand == 1:
        qCount += 1
        x = randint(1,100)
        y = randint(1,100)
        print "What is %d %s %d\n" % (x,"+",y)
        answer = int(raw_input(""))
        if answer == x+y:
            scoreCount += 1
            print "That is correct!\n"
        elif answer != x+y:
            print "That is not correct.\n"
    elif rand == 2:
        qCount += 1
        x = randint(10,200)
        y = randint(1,x)
        print "What is %d %s %d\n" % (x,"-",y)
        answer = int(raw_input(""))
        if answer == x-y:
            scoreCount += 1
            print "That is correct!\n"
        elif answer != x-y:
            print "That is not correct.\n"
    elif rand == 3:
        qCount += 1
        x = randint(1,20)
        y = randint(1,20)
        print "What is %d %s %d\n" % (x,"*",y)
        answer = int(raw_input(""))
        if answer == x*y:
            scoreCount += 1
            print "That is correct!\n"
        elif answer != x*y:
            print "That is not correct.\n"

raw_input("That's all the questions I have for you. To continue press Enter...")
print "You got %d out of %d questions right." % (scoreCount,qCount)
Logged
Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1417


/* No comment */


WWW
« Reply #1 on: September 29, 2008, 08:52:25 AM »

My Python's a little rusty, but shouldn't this:
Code:
if nOfQs > (50 or nOfQs < 0) and frust >= 6:
be this:
Code:
if (nOfQs > 50 or nOfQs < 0) and frust >= 6:
?
Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
Creepy Doll
Full Member
***
Offline Offline

Gender: Male
Posts: 121

In a town in the woods at the top of a hill...


« Reply #2 on: September 30, 2008, 01:49:24 AM »

I don't know.... maybe. It works the way it is, but you're probably onto something here. In any case your suggestion seems just slightly more readable.
Logged
Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1417


/* No comment */


WWW
« Reply #3 on: September 30, 2008, 03:51:23 AM »

Yeah, looking at it, it would work fine. Technically, there's nothing wrong with it, it's just a bit... odd, and probably not what you were intending to code.
Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
Creepy Doll
Full Member
***
Offline Offline

Gender: Male
Posts: 121

In a town in the woods at the top of a hill...


« Reply #4 on: October 01, 2008, 12:17:48 AM »

Woah, I just saw what was so stupid about that line! I didn't really notice it before, even when you brought it up.
Still, it works as it should (or at least appears to).
Logged
Brackenwood
   

 Logged
Pages: [1]   Go Up
Print
Jump to:  

Theme by Pieter, based on Black Rain by Crip Powered by SMF 1.1.16 | SMF © 2011, Simple Machines XHTML | CSS

Page created in 0.043 seconds with 24 queries.