Re: [Tutor] Loops and modules

2007-12-06 Thread bhaaluu
On Dec 6, 2007 8:38 AM, richard west <[EMAIL PROTECTED]> wrote:
>  heres a partial solution. theres no error checking on the Raw Input and you
> have to type in you last number and press return, before the loop will
> break, but its a start!

And modifying  your modifications makes it work even a little better:
###
#!/usr/bin/python

import random
import time
import threading

class Timer(threading.Thread):
def __init__(self, seconds):
   self.runTime = seconds
   threading.Thread.__init__(self)
def run(self):
global running
time.sleep(self.runTime)
print " "
print "Buzzz!!! Time's up!"
running = False

t = Timer(30)
t.start()
startNum = random.choice(range(1, 9))
newNum = startNum + 7
score = 0
running = True
print 'Start with the number ', startNum, '.  Then continuously add 7
to that number until the timer runs out.  You have 30 seconds.'

while running:
if running == True:
 answer = int(raw_input('Enter your answer: '))
 if answer == newNum:
   print 'That is correct!  Keep going.'
   score = score + 5
   newNum = newNum + 7
   print 'Your score is ', score
 else:
   print 'That is incorrect.  Please try again.'
else:
answer = 0
print ' '
print 'Your total score was: ', score
###

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m

> #!/usr/bin/python
> # Filename : math_test.py
>
> import time
> import threading
> class Timer(threading.Thread):
> def __init__(self, seconds):
>self.runTime = seconds
>threading.Thread.__init__(self)
> def run(self):
> global running
> time.sleep(self.runTime)
> print " "
> print "Buzzz!!! Time's up!"
> running = False
> t = Timer(30)
> t.start()
>
> import random
> startNum = random.choice(range(1, 9))
> newNum = startNum + 7 # im assuming you want the first number the user to
> type as the startnum +7,its not too clear.
> score = 0
> running = True
>
> print 'Start with the number ', startNum, '.  Then continuously add 7 to
> that number until the timer runs out.  You have 30 seconds.'
>
> while running:
> print running
> answer = int(raw_input('Enter your answer: '))
> if running == True:
>  if answer == newNum:
>print 'That is correct!  Keep going.'
>score = score + 5
> newNum = newNum+7
>print 'Your score is ', score
> else:
>print 'That is incorrect.  Please try again.'
> print ' '
> print 'you total score was ', score
>
> On Dec 6, 2007 6:15 PM, <[EMAIL PROTECTED]> wrote:
> > Send Tutor mailing list submissions to
> >tutor@python.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> > http://mail.python.org/mailman/listinfo/tutor
> > or, via email, send a message with subject or body 'help' to
> >[EMAIL PROTECTED]
> >
> > You can reach the person managing the list at
> >[EMAIL PROTECTED]
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Tutor digest..."
> >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Loops and modules

2007-12-06 Thread richard west
 heres a partial solution. theres no error checking on the Raw Input and you
have to type in you last number and press return, before the loop will
break, but its a start!

#!/usr/bin/python
# Filename : math_test.py

import time
import threading
class Timer(threading.Thread):
def __init__(self, seconds):
   self.runTime = seconds
   threading.Thread.__init__(self)
def run(self):
global running
time.sleep(self.runTime)
print " "
print "Buzzz!!! Time's up!"
running = False
t = Timer(30)
t.start()

import random
startNum = random.choice(range(1, 9))
newNum = startNum + 7 # im assuming you want the first number the user to
type as the startnum +7,its not too clear.
score = 0
running = True

print 'Start with the number ', startNum, '.  Then continuously add 7 to
that number until the timer runs out.  You have 30 seconds.'

while running:
print running
answer = int(raw_input('Enter your answer: '))
if running == True:
 if answer == newNum:
   print 'That is correct!  Keep going.'
   score = score + 5
newNum = newNum+7
   print 'Your score is ', score
else:
   print 'That is incorrect.  Please try again.'
print ' '
print 'you total score was ', score

On Dec 6, 2007 6:15 PM, <[EMAIL PROTECTED]> wrote:

> Send Tutor mailing list submissions to
>tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>[EMAIL PROTECTED]
>
> You can reach the person managing the list at
>[EMAIL PROTECTED]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>   1. Re: Best way of learning (bhaaluu)
>   2. Re: how to accept an integer? (Alan Gauld)
>   3. Mail? What's that? (Ricardo Ar?oz)
>   4. Re: Button 1 Motion Event (Luke Paireepinart)
>   5. While Loops and Modules (earlylight publishing)
>   6. Re: Mail? What's that? (Luke Paireepinart)
>   7. Re: Best way of learning (Remco Gerlich)
>
>
> --
>
> Message: 1
> Date: Wed, 5 Dec 2007 18:50:04 -0500
> From: bhaaluu <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Best way of learning
> To: andy <[EMAIL PROTECTED]>
> Cc: tutor@python.org
> Message-ID:
><[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Dec 5, 2007 5:43 PM, andy <[EMAIL PROTECTED]> wrote:
> > Dear Pythonistas
> >
> [snip]
> >
> > So, after this long-winded introduction, I was hoping to pick the wisdom
> > of this list to get some pointers of what to do/not to do to make the
> > most effective use of the few hours I have to learn how to program using
> > Python. So, any advice for someone in their mid-40s who would like to
> > learn Python in a more methodical and effective manner?
> >
> > Thanks in anticipation.
> >
> > Andy
>
> It sounds to me like a good book or two would be just the thing for you.
> May I suggest:
> Learning Python by Mark Lutz
> and
> Programming Python Third Edition by the same author.
>
> Happy Programming!
> --
> b h a a l u u at g m a i l dot c o m
> http://www.geocities.com/ek.bhaaluu/python/index.html
>
>
> --
>
> Message: 2
> Date: Wed, 5 Dec 2007 23:51:59 -
> From: "Alan Gauld" <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] how to accept an integer?
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>reply-type=original
>
> "Mahesh N" <[EMAIL PROTECTED]> wrote
>
> > More over i find python to be a little sluggish after having worked
> > with C
> > and Java.
>
> If you translate C or Java code into python you will usually
> get a less than optimal implementation. Python should be
> barely slower than Java and often faster. Compared to
> C - yes there is a slow-down.
>
> But even in C you can use tools like Psycho and Pyrex to
> speed up critical sections to near C speeds if the problem fits.
> Or rewrite the critical section in C and wrap it as a module
> using SWIG. Thats how most of the performance ritical modules
> in the library are written. Where the major bottleneck is I/O
> work like database disk access or GUI or network sockets
> then you should find Python fast enough.
>
> > can someone temme where python is most applicable?
> > server side scripting? am i guessing it right?
>
> Python has been used in almost every form of programming
> from image processing and database manipulation to games
> programming and web server development. Do a search on
> Source Forge for projects using Python for an example of
> the variety.
>
> I'd avoid operating systems, device drivers and hard real-time
> applications though.
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http: