[Tutor] Loops and modules
bhaaluu
bhaaluu at gmail.com
Thu Dec 6 16:19:00 CET 2007
On Dec 6, 2007 8:38 AM, richard west <richardbwest at gmail.com> 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, <tutor-request at python.org> wrote:
> > Send Tutor mailing list submissions to
> > tutor at 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
> > tutor-request at python.org
> >
> > You can reach the person managing the list at
> > tutor-owner at python.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Tutor digest..."
> >
More information about the Tutor
mailing list