Re: [Tutor] decision loops

2015-02-01 Thread Steven D'Aprano
Hello Daniel, and welcome! On Sat, Jan 31, 2015 at 08:54:48PM -0500, Daniel M wrote: Hello. I'm a complete beginner and I’m trying to write a very basic script to convert temperatures, just for some practice. I have that part down, but I can’t figure out how to make the script switch between

[Tutor] decision loops

2015-02-01 Thread Daniel M
Hello. I'm a complete beginner and I’m trying to write a very basic script to convert temperatures, just for some practice. I have that part down, but I can’t figure out how to make the script switch between the two. What I would like it to do is let the user go back to the “What do you wish to

Re: [Tutor] decision loops

2015-02-01 Thread Alan Gauld
On 01/02/15 01:54, Daniel M wrote: I can’t figure out how to make the script switch between the two. What I would like it to do is let the user go back to the “What do you wish to convert?” part when a character is entered instead of a number for “temperature?”. I tried using That's quite a

[Tutor] While loops

2012-07-07 Thread myles broomes
I am currently coding a 'text-based adventure game', and im having a bit of trouble with while loops. Here is my code so far: #Text-based Adventure RPG #The player travels through different towns and dungeons #The overall goal of the game is simple; the player must make it to the final town,

Re: [Tutor] While loops

2012-07-07 Thread Emile van Sebille
On 7/7/2012 5:57 AM myles broomes said... I am currently coding a 'text-based adventure game', and im having a bit of trouble with while loops. Here is my code so far: Please paste in the traceback you're getting, and please set your mail client program for plain text when posting. What I

Re: [Tutor] While loops

2012-07-07 Thread Alan Gauld
On 07/07/12 13:57, myles broomes wrote: I am currently coding a 'text-based adventure game', and im having a bit of trouble with while loops. Here is my code so far: What kind of trouble? You have lots of while loops, which loop? And do you get an error message? If so please post it - all of

[Tutor] while loops

2011-12-14 Thread rog capp
# Guess my number # # The computer picks a random number between 1 and 100 # The player tries to guess it and the computer lets # the player know if the guess is to high, to low # or right on the money import random print(\tWelcome to 'Guess My Number'!) print(I'm thinking of a number between 1

Re: [Tutor] while loops

2011-12-14 Thread Steven D'Aprano
rog capp wrote: [...] # Guessing loop while guess != the_number: if guess the_number: print(Lowere...) else: print(Higher...) guess = int(input(Take a guess: )) tries += 1 print(good job) input(\n\nPress the enter key to exit.) This is a program from Python

Re: [Tutor] while loops

2011-12-14 Thread Dave Angel
On 12/14/2011 05:41 PM, rog capp wrote: # Guess my number # # The computer picks a random number between 1 and 100 # The player tries to guess it and the computer lets # the player know if the guess is to high, to low # or right on the money import random print(\tWelcome to 'Guess My

Re: [Tutor] while loops

2011-12-14 Thread Alan Gauld
On 14/12/11 22:41, rog capp wrote: # Guessing loop while guess != the_number: if guess the_number: else: guess = int(input(Take a guess: )) tries += 1 If he/she fails to guess the number after a certain number of attempts then it displays a message about his failure.It

Re: [Tutor] while loops

2011-12-14 Thread Prasad, Ramit
-Original Message- From: tutor-bounces+ramit.prasad=jpmorgan@python.org [mailto:tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of rog capp Sent: Wednesday, December 14, 2011 4:41 PM To: tutor@python.org Subject: [Tutor] while loops # Guess my number # # The computer

Re: [Tutor] nested loops

2011-02-07 Thread Michael M Mason
Alan Gauld wrote:- Wayne Werner waynejwer...@gmail.com wrote found = False highscore = 0 alignment = somealignment for x in something and not found: for y in somethingelse and not found: for z in evenmoresomething: if x+y+z highscore:

Re: [Tutor] nested loops

2011-02-07 Thread Steven D'Aprano
Alan Gauld wrote: Wayne Werner waynejwer...@gmail.com wrote You probably want to add a sentinel to break out of the outer loops too: I don't think you want to break out of *any* of the loops. Otherwise you will skip testing combinations. In your example, the first time you set highscore and

Re: [Tutor] nested loops

2011-02-07 Thread Alan Gauld
Steven D'Aprano st...@pearwood.info wrote I don't think you want to break out of *any* of the loops. Otherwise you will skip testing combinations. In that case I misread the OP. I thought he specifically wanted to avoid testing all the options and exit when he reached his target. In your

[Tutor] for loops when there is only one row in the result - is there an alternative?

2010-11-25 Thread Rance Hall
Im using the py-postgresql module (docs here: http://python.projects.postgresql.org/docs/1.0/) in a python 3.1 environment to connect to my database. so far everything is working, but I'm having trouble understanding the structure of the variable returned by a select statement Generally you

Re: [Tutor] for loops when there is only one row in the result - is there an alternative?

2010-11-25 Thread Steven D'Aprano
Rance Hall wrote: Generally you have something like this: clientlist = get_clients() # where get_clients is a prepared sql statement. normally you would get the individual rows like this: for row in clientlist: do stuff which is great for a long list of results. But I'm running into

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread Nithya Nisha
Hi there, This is the Code. Please check it.It is working fine. import random headsCount = 0 tailsCount = 0 count = 1 while count = 100: coin = random.randrange(2) if coin == 0: headsCount += 1 else: tailsCount += 1 count += 1 print The

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread Nithya Nisha
Thankyou..!!! Regards, Nithya On Tue, Nov 16, 2010 at 1:51 PM, Luke Pettit petl...@gmail.com wrote: Arrr thats better Nithya it works fine now. I had it working fine before it was just coming up with that strange result of 73 and 100 when I copied the code into wing to check it out in order

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread Stephanie Dawn Samson
Greetings, As a thread starter, I thought I should write the rewritten code I got that others helped me get to, since this thread is still going on. # Coin Flips# The program flips a coin 100 times and then# tells you the number of heads and tailsimport random print \aprint \tWelcome to 'Coin

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread Alan Gauld
Stephanie Dawn Samson sd...@live.ca wrote thought I should write the rewritten code I got that others helped me get to By applying a couple of other ideas that have been suggested you get something shorter and arguably slightly clearer: # Coin Flips # The program flips a coin 100 times and

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread bob gailer
Just for the heck of it: heads = sum(random.randrange(2) for i in range(100)) -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-15 Thread Nithya Nisha
Hi Tom, Your code is almost correct. Little mistake is there.The random number generate should be in while loop. import random # set the coin headsCount = 0 tailsCount = 0 count = 0 # the loop while count 100: #If you declare count =

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-15 Thread Luke Pettit
When I run this code (I'm also a noob) I get this result:- [evaluate lines 1-22 from untitled-1.py] The number of heads was 73 The number of tails was 100 Press the enter key to exit. # Surely, if flipping a single coin 100 times your total number of heads and tails should add up to 100 # not

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-15 Thread Nithya Nisha
Hi Tom, Your code is almost correct. Little mistake is there.The random number generate should be in while loop. import random # set the coin headsCount = 0 tailsCount = 0 count = 0 # the loop while count 100: #If you declare count = 0. The while loop

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-15 Thread Dave Angel
When I run this code (I'm also a noob) I get this result:- [evaluate lines 1-22 from untitled-1.py] The number of heads was 73 The number of tails was 100 Press the enter key to exit. # Surely, if flipping a single coin 100 times your total number of heads and tails should add up to 100 #

Re: [Tutor] While Loops: Coin Flip Game

2010-11-14 Thread Hugo Arts
On Sun, Nov 14, 2010 at 11:16 PM, Dawn Samson sd...@live.ca wrote: Greetings, I'm a Python beginner and working my way through Michael Dawson's Python Programming for the Absolute Beginner. I'm stuck in a particular challenge that asks me to write a program that flips a coin 100 times and then

Re: [Tutor] While Loops: Coin Flip Game

2010-11-14 Thread Steven D'Aprano
Dawn Samson wrote: I've been trying to work on this challenge for a while now and can't get it to work (either it has 100 heads or 100 tails). Unfortunately your code has been mangled in the email, but I can guess your problem: you need to set coin = random.randrange(2) each time through

Re: [Tutor] While Loops: Coin Flip Game

2010-11-14 Thread Stephanie Dawn Samson
Thanks everyone! I should be using algorithms for even such programs at my level. The solution to reiterate the coin flip every time in the loop works. Thanks a lot! Dawn ___ Tutor maillist -

Re: [Tutor] While Loops: Coin Flip Game

2010-11-14 Thread Adam Bark
On 14/11/10 22:16, Dawn Samson wrote: Greetings, I'm a Python beginner and working my way through Michael Dawson's Python Programming for the Absolute Beginner. I'm stuck in a particular challenge that asks me to write a program that flips a coin 100 times and then tells you the number of

Re: [Tutor] While Loops: Coin Flip Game

2010-11-14 Thread Robert Berman
From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Dawn Samson Sent: Sunday, November 14, 2010 5:17 PM To: tutor@python.org Subject: [Tutor] While Loops: Coin Flip Game Greetings, I'm a Python beginner and working my way through

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-14 Thread Thomas C. Hicks
On Sun, 14 Nov 2010 17:16:36 -0500 Dawn Samson sd...@live.ca wrote: Greetings, I'm a Python beginner and working my way through Michael Dawson's Python Programming for the Absolute Beginner. I'm stuck in a particular challenge that asks me to write a program that flips a coin 100 times and

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-07 Thread Alan Gauld
Alex Hall mehg...@gmail.com wrote I am not sure how else to explain it. I want to loop until the value of a variable changes, but while that loop is taking place, the user should be able to perform actions set up in a wx.AcceleratorTable. And here we have the critical clue. You are trying to

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-07 Thread Walter Prins
On 7 June 2010 02:37, Alex Hall mehg...@gmail.com wrote: I am not sure how else to explain it. I want to loop until the value of a variable changes, but while that loop is taking place, the user should be able to perform actions set up in a wx.AcceleratorTable. Looping, though, causes Windows

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-07 Thread Mark Lawrence
On 07/06/2010 01:44, Alex Hall wrote: Further to the other comments that you've had, could you please refer to the following, thanks. http://www.catb.org/~esr/faqs/smart-questions.html Kindest regards. Mark Lawrence ___ Tutor maillist -

Re: [Tutor] while loops / listeners

2010-06-07 Thread Francesco Loffredo
Hi all, I think that simply erasing those continue statements will let Python respond again. Those statements are both useless and damaging, because the following time.sleep(.1) statements will NEVER be executed. And this, in turn, is IMHO the reason why Python stops responding: it lacks the

[Tutor] while loops causing python.exe to crash on windows

2010-06-06 Thread Alex Hall
-- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-06 Thread bob gailer
On 6/6/2010 8:44 PM, Alex Hall wrote: -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com;http://www.facebook.com/mehgcap What is your question? -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist -

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-06 Thread Alex Hall
On 6/6/10, bob gailer bgai...@gmail.com wrote: On 6/6/2010 8:44 PM, Alex Hall wrote: -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com;http://www.facebook.com/mehgcap What is your question? -- Bob Gailer 919-636-4239 Chapel Hill NC Why would that code cause

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-06 Thread Lie Ryan
On 06/07/10 11:08, Alex Hall wrote: On 6/6/10, bob gailer bgai...@gmail.com wrote: On 6/6/2010 8:44 PM, Alex Hall wrote: -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com;http://www.facebook.com/mehgcap What is your question? -- Bob Gailer 919-636-4239 Chapel

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-06 Thread Alex Hall
On 6/6/10, Lie Ryan lie.1...@gmail.com wrote: On 06/07/10 11:08, Alex Hall wrote: On 6/6/10, bob gailer bgai...@gmail.com wrote: On 6/6/2010 8:44 PM, Alex Hall wrote: -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com;http://www.facebook.com/mehgcap What is your

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-06 Thread bob gailer
On 6/6/2010 9:37 PM, Alex Hall wrote: On 6/6/10, Lie Ryanlie.1...@gmail.com wrote: On 06/07/10 11:08, Alex Hall wrote: On 6/6/10, bob gailerbgai...@gmail.com wrote: On 6/6/2010 8:44 PM, Alex Hall wrote: -- Have a great day, Alex (msg sent from GMail website)

[Tutor] while loops / listeners

2010-06-06 Thread Alex Hall
Hi all, First off, I apologize to the list for my previous thread; somehow, despite my having written the post, it ended up blank () I have a main loop which will continue for as long as neither player1 nor player2 has won. Inside that loop I have a call to a function which should basically

[Tutor] Fw: loops

2009-12-08 Thread Richard Hultgren
- Forwarded Message From: Richard Hultgren hultgren1...@yahoo.com To: tutor@python.org Sent: Mon, December 7, 2009 2:53:40 PM Subject: loops I'm quite new but determined.  Can you explain to me, step by step, what is going on in the computer in this loop.  I hope I am not being too

Re: [Tutor] Fw: loops

2009-12-08 Thread Serdar Tumgoren
- Forwarded Message From: Richard Hultgren hultgren1...@yahoo.com To: tutor@python.org Sent: Mon, December 7, 2009 2:53:40 PM Subject: loops I'm quite new but determined.  Can you explain to me, step by step, what is going on in the computer in this loop.  I hope I am not being too

Re: [Tutor] Fw: loops

2009-12-08 Thread christopher . henk
You should probably read some of the links sent to you earlier but here is a stab at an explanation. Richard Hultgren wrote on 12/08/2009 10:36:08 AM: - Forwarded Message From: Richard Hultgren hultgren1...@yahoo.com To: tutor@python.org Sent: Mon, December 7, 2009 2:53:40 PM

Re: [Tutor] Fw: loops

2009-12-08 Thread Alan Gauld
Serdar Tumgoren zstumgo...@gmail.com wrote http://www.freenetpages.co.uk/hp/alan.gauld/ Note the new URL in my sig. Freenet are due to close this site soon. Its been locked for over a year. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/

Re: [Tutor] 'for' loops

2008-12-07 Thread Lie Ryan
On Tue, 02 Dec 2008 01:17:41 +, Alan Gauld wrote: while loops are used much less in Python than in other languages because for loops are so powerful. Actually, I think python's for-loop is so powerful that while loop could be removed from the language and no power would be lost (although

[Tutor] 'for' loops

2008-12-01 Thread WM.
I recently asked a question about 'for' loops, expecting them to be similar to 'for-next' loops. I have looked at several on-line tutors but am still in the dark about what 'for' loops do. Does anyone have a plain English about the use of 'for' loops? Are 'while' loops the only way Python runs

Re: [Tutor] 'for' loops

2008-12-01 Thread Steve Willoughby
On Mon, Dec 01, 2008 at 04:44:02PM -0800, WM. wrote: I recently asked a question about 'for' loops, expecting them to be similar to 'for-next' loops. I have looked at several on-line tutors but am still in the dark about what 'for' loops do. Does anyone have a plain English about the use of

Re: [Tutor] 'for' loops

2008-12-01 Thread W W
On Mon, Dec 1, 2008 at 6:44 PM, WM. [EMAIL PROTECTED] wrote: I recently asked a question about 'for' loops, expecting them to be similar to 'for-next' loops. I have looked at several on-line tutors but am still in the dark about what 'for' loops do. Does anyone have a plain English about the

Re: [Tutor] 'for' loops

2008-12-01 Thread John Fouhy
On 02/12/2008, WM. [EMAIL PROTECTED] wrote: I recently asked a question about 'for' loops, expecting them to be similar to 'for-next' loops. I have looked at several on-line tutors but am still in the dark about what 'for' loops do. Does anyone have a plain English about the use of 'for'

Re: [Tutor] 'for' loops

2008-12-01 Thread Alan Gauld
WM. [EMAIL PROTECTED] wrote I recently asked a question about 'for' loops, expecting them to be similar to 'for-next' loops. I have looked at several on-line tutors but am still in the dark about what 'for' loops do. Python for loops are like foreach loops in other languages. A Python for

Re: [Tutor] 'for' loops

2008-12-01 Thread Kent Johnson
On Mon, Dec 1, 2008 at 7:56 PM, John Fouhy [EMAIL PROTECTED] wrote: [1] Technically, it iterates over an iterator, which you can think of as an object that behaves like a list when you throw it at a for loop. The object of the 'in' must be an iterable, which is an object that can produce an

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-28 Thread Eric Abrahamsen
I finally got my iterator-based version working, only to discover that it's nearly four times slower than the brute-force multiple-loops version I started with! Then I tried just adding an incrementing index to the loop, so that each loop only ran through self.events[last_index:], but that

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-28 Thread Lie Ryan
Just for the sake of argument, here's the principle I'm working from: # lst = range(10) iterlst = iter(lst) iterlst.next() 0 for x in iterlst: ... if x 5: ... print x ... else: ... break ... 1 2 3 4 for x in iterlst: ... print x ...

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Kent Johnson
On Tue, Aug 26, 2008 at 1:36 AM, Eric Abrahamsen [EMAIL PROTECTED] wrote: So my test case: a Month has a 'child' attribute pointing at Week, which has a 'child' attribute pointing at Day, so they all know what kind of child instances iteration should produce. With nested loops, a Month

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Eric Abrahamsen
On Aug 26, 2008, at 7:20 PM, Kent Johnson wrote: On Tue, Aug 26, 2008 at 1:36 AM, Eric Abrahamsen [EMAIL PROTECTED] wrote: So my test case: a Month has a 'child' attribute pointing at Week, which has a 'child' attribute pointing at Day, so they all know what kind of child instances

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Alan Gauld
Eric Abrahamsen [EMAIL PROTECTED] wrote So that's why I'm creating the iterator outside of the while loop in the original code, and then using a repeated for loop with a break to step through all the events only once. Of course, the fact that 5 isn't in there probably points to the source

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Kent Johnson
On Tue, Aug 26, 2008 at 1:24 PM, Eric Abrahamsen [EMAIL PROTECTED] wrote: On Aug 26, 2008, at 7:20 PM, Kent Johnson wrote: If all you want to do with the nested Month, etc is to iterate the events in them, you could probably use a shared iterator. It would have to be able to push-back items

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-25 Thread Eric Abrahamsen
Okay I think I'm onto something, more iterator-related stuff. If I can make self.events an iterator, then run a for loop on it, breaking out of the loop when the events' date attributes get too high. Then on the next run through, that same for loop should pick up where it left off, right?

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-25 Thread Kent Johnson
I'm not following your code very well. I don't understand the relationship between the first loop and the iter_children() function. A couple of things that might help: - Django QuerySets can be qualified with additional tests, so you could have each of your month/week/etc classes have its own

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-25 Thread Eric Abrahamsen
I do apologize for the large quantities of confusing description – articulating the problem here has helped me understand exactly what it is I'm after (though it hasn't improved my code!), and I've got a better grasp of the problem now than I did when I first asked. It isn't so much that I

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-24 Thread Eric Abrahamsen
On Aug 24, 2008, at 7:20 PM, Kent Johnson wrote: Forwarding to the list with my reply. Please use Reply All to reply to the list. Grr, sorry, I keep forgetting... On Sun, Aug 24, 2008 at 1:02 AM, Eric Abrahamsen [EMAIL PROTECTED] wrote: On Aug 23, 2008, at 11:22 PM, Kent Johnson

[Tutor] __iter__ loops, partitioning list among children

2008-08-23 Thread Eric Abrahamsen
Hi, I've got a problem that takes a bit of explaining, but it's relatively simple when you get down to it. This is another django-related thing, but the issue itself is pure python. I made a custom class, called an EventEngine, which represents a span of time. You initialize it with a

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-23 Thread Kent Johnson
On Sat, Aug 23, 2008 at 6:47 AM, Eric Abrahamsen [EMAIL PROTECTED] wrote: At first I thought the bisect module was the way to go, but it is too tightly tied to integer list indices, and works very awkwardly when bisecting on datetime attributes. I'm not sure what the problem is with bisect (to

Re: [Tutor] For Loops and nested loops

2008-08-16 Thread bob gailer
Umesh Singhal wrote: Hi im still relatively new to python and i am designing a multiplication table that enables a user to input the size of the times table unfortunately ive stumbled on the nested loops this is what i have right now: a=raw_input('please enter a number') b=int(a) n=b+1 for

Re: [Tutor] For Loops and nested loops

2008-08-16 Thread Steve Willoughby
On Sat, Aug 16, 2008 at 06:33:42AM +0100, Umesh Singhal wrote: Hi im still relatively new to python and i am designing a multiplication table that enables a user to input the size of the times table unfortunately ive stumbled on the nested loops this is what i have right now: Is this a

Re: [Tutor] For Loops and nested loops

2008-08-16 Thread Lie Ryan
On Sat, 2008-08-16 at 18:07 +0200, [EMAIL PROTECTED] wrote: Message: 1 Date: Sat, 16 Aug 2008 06:33:42 +0100 From: Umesh Singhal [EMAIL PROTECTED] Subject: [Tutor] For Loops and nested loops To: tutor@python.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=windows-1252

Re: [Tutor] For Loops and nested loops

2008-08-16 Thread bob gailer
PLEASE REPLY TO THE GROUP NOT JUST ME. Did you miss my request for that (reply-all)? Umesh Singhal wrote: Hi Bob, unfortunately when i pasted in the code it seems to have gone wrong this is how it is at the moment with the correct indentation for the nested loop: code:

Re: [Tutor] While Loops and Modules

2007-12-06 Thread bhaaluu
Greetings, On Dec 6, 2007 12:44 AM, earlylight publishing [EMAIL PROTECTED] wrote: Hello again to all the wonderfully helpful folks on this list. Today I did my Google homework and I found this neat bit of code for a countdown timer. import time import threading class

[Tutor] While Loops and Modules

2007-12-05 Thread earlylight publishing
Hello again to all the wonderfully helpful folks on this list. Today I did my Google homework and I found this neat bit of code for a countdown timer. import time import threading class Timer(threading.Thread): def __init__(self, seconds): self.runTime = seconds

[Tutor] Infinite Loops (and threads)

2006-12-24 Thread Jonathan McManus
Hi all, Just a quick question, really. Is there any good way to have an infinite loop in a program, without said infinite loop eating up the CPU? I've tried the trick of adding a pause (time.sleep(0.01)) somewhere in the loop, and this appears to have worked on a basic infinite loop, but this

Re: [Tutor] Infinite Loops (and threads)

2006-12-24 Thread Kent Johnson
Jonathan McManus wrote: Hi all, Just a quick question, really. Is there any good way to have an infinite loop in a program, without said infinite loop eating up the CPU? I've tried the trick of adding a pause (time.sleep(0.01)) somewhere in the loop, and this appears to have worked on a

Re: [Tutor] Infinite Loops (and threads)

2006-12-24 Thread Luke Paireepinart
Kent Johnson wrote: Jonathan McManus wrote: Hi all, Just a quick question, really. Is there any good way to have an infinite loop in a program, without said infinite loop eating up the CPU? I've tried the trick of adding a pause (time.sleep(0.01)) somewhere in the loop, and this appears

Re: [Tutor] Infinite Loops (and threads)

2006-12-24 Thread Adam Bark
On 24/12/06, Luke Paireepinart [EMAIL PROTECTED] wrote: Kent Johnson wrote: Jonathan McManus wrote: Hi all, Just a quick question, really. Is there any good way to have an infinite loop in a program, without said infinite loop eating up the CPU? I've tried the trick of adding a pause

Re: [Tutor] Infinite Loops (and threads)

2006-12-24 Thread زياد بن عبدالعزيز الباتلي
Luke Paireepinart [EMAIL PROTECTED] On Sun, 24 Dec 2006 10:02:19 -0600 wrote: Kent Johnson wrote: Kent et. al., I'm writing something that has to do with sockets. I need to recv any incoming packets from the socket. I will have potentially hundreds of separate sockets open in a single

Re: [Tutor] Infinite Loops (and threads)

2006-12-24 Thread Kent Johnson
Luke Paireepinart wrote: Kent et. al., I'm writing something that has to do with sockets. I need to recv any incoming packets from the socket. I will have potentially hundreds of separate sockets open in a single application. I was just going to create a thread for each, so I could

Re: [Tutor] foreach loops

2006-09-12 Thread Alan Gauld
Does python have foreach loops? I don't see any mention of them in the docs. Am I going to have to use Perl (gasp!) if I want my beloved foreach loop? Its called a for loop in Python... Or is there some extra magic in the Perl version that I'm missing? Alan G.

Re: [Tutor] foreach loops

2006-09-12 Thread Alan Gauld
I was thinking more along the lines of this: A C++ for loop: This is exactly NOT a foreach loop, its a vanilla for loop. #include iostream using std::cout; int main() { for (int i = 0; i 10; i++) { cout i \n; } for i in range(10): print i Alan G.

[Tutor] foreach loops

2006-09-11 Thread Christopher Spears
Does python have foreach loops? I don't see any mention of them in the docs. Am I going to have to use Perl (gasp!) if I want my beloved foreach loop? -Chris ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] foreach loops

2006-09-11 Thread Danny Yoo
Does python have foreach loops? I don't see any mention of them in the docs. Am I going to have to use Perl (gasp!) if I want my beloved foreach loop? Can you show an example of a Perl foreach loop? Perhaps someone can help translate it into idiomatic Python. Good luck!

Re: [Tutor] foreach loops

2006-09-11 Thread Luke Paireepinart
Danny Yoo wrote: Does python have foreach loops? I don't see any mention of them in the docs. Am I going to have to use Perl (gasp!) if I want my beloved foreach loop? Can you show an example of a Perl foreach loop? Perhaps someone can help translate it into idiomatic Python.

Re: [Tutor] foreach loops

2006-09-11 Thread Luke Paireepinart
Christopher Spears wrote: Hmmm...Perl is probably a bad example. My apologies. I was thinking more along the lines of this: A C++ for loop: #include iostream using std::cout; int main() { for (int i = 0; i 10; i++) { cout i \n; }

Re: [Tutor] foreach loops

2006-09-11 Thread Jordan Greenberg
Christopher Spears wrote: Hmmm...Perl is probably a bad example. My apologies. I was thinking more along the lines of this: A C++ for loop: #include iostream using std::cout; int main() { for (int i = 0; i 10; i++) { cout i \n; }

Re: [Tutor] no loops

2006-07-12 Thread Alan Gauld
def increment(time, seconds): time.seconds = time.seconds + seconds while time.seconds = 60: time.seconds = time.seconds - 60 time.minutes = time.minutes + 1 Tale a look at what this loop is doing. Think about its purpose. If you werre doing this with paper and pencil would you

[Tutor] no loops

2006-07-11 Thread Christopher Spears
I am working on another problem from How To Think Like A Computer Scientist. Here is a function: def increment(time, seconds): time.seconds = time.seconds + seconds while time.seconds = 60: time.seconds = time.seconds - 60 time.minutes = time.minutes + 1 while time.minutes = 60:

Re: [Tutor] no loops

2006-07-11 Thread Gregor Lingl
Christopher Spears schrieb: IF you know that it's 2 seconds after midnight, how many hours, minutes, seconds after midnight ist this. If you should compute this by hand, how would you proceed? Best wishes, Gregor I am working on another problem from How To Think Like A Computer

Re: [Tutor] no loops

2006-07-11 Thread John Fouhy
On 12/07/06, Christopher Spears [EMAIL PROTECTED] wrote: Now the exercise is: As an exercise, rewrite this function so that it doesn't contain any loops. I have been staring at this function and drawing a blank. Something tells me that I need to use iteration, but I am not sure how I could

Re: [Tutor] no loops

2006-07-11 Thread Marc Poulin
--- John Fouhy [EMAIL PROTECTED] wrote: On 12/07/06, Christopher Spears [EMAIL PROTECTED] wrote: Now the exercise is: As an exercise, rewrite this function so that it doesn't contain any loops. I have been staring at this function and drawing a blank. Something tells me that I

Re: [Tutor] no loops

2006-07-11 Thread Bob Gailer
Christopher Spears wrote: I am working on another problem from How To Think Like A Computer Scientist. Here is a function: def increment(time, seconds): time.seconds = time.seconds + seconds while time.seconds = 60: time.seconds = time.seconds - 60 time.minutes = time.minutes

[Tutor] for loops over multiple lists of the same length

2006-06-22 Thread Emily Fortuna
I feel like there should be a better way to do this process: Can you please help? (This is trivial example code I created off the top of my head, but the same concept that I am trying to do elsewhere.) class Person(object): def __init__(self, first_name, age, fav_color):

Re: [Tutor] for loops over multiple lists of the same length

2006-06-22 Thread Kent Johnson
Emily Fortuna wrote: I feel like there should be a better way to do this process: Can you please help? (This is trivial example code I created off the top of my head, but the same concept that I am trying to do elsewhere.) class Person(object): def __init__(self, first_name, age,

Re: [Tutor] for loops over multiple lists of the same length

2006-06-22 Thread Shantanoo Mahajan
+++ Emily Fortuna [22-06-06 13:22 -0400]: | I feel like there should be a better way to do this process: | Can you please help? | (This is trivial example code I created off the top of my head, but the | same concept that I am trying to do elsewhere.) | | class Person(object): | def

Re: [Tutor] for loops

2006-04-11 Thread David Rock
* josip [EMAIL PROTECTED] [2006-04-11 09:13]: I have problem with this question. Can someone show me the code and than explain it? Write a Python program to print out the following shape. You are expected to use two for loops (these must be nested) to solve this problem.

Re: [Tutor] for loops

2006-04-11 Thread Alan Gauld
Write a Python program to print out the following shape. You are expected to use two for loops (these must be nested) to solve this problem. output: * * * * * * * * * * * * * * That looks a lot like homework. I agree and very poor homework too. I

Re: [Tutor] for loops and exceptions

2006-03-30 Thread Kent Johnson
Matthew White wrote: Hello, From a general style and/or programmatic perspective, which is a better way to write this bit of code? Hmm, neither? try: (dn, attrs) = conn.search_s(search_base, search_scope, search_filter, search_attrs): except Exception, e: warn_the_user(e)

[Tutor] for loops and exceptions

2006-03-29 Thread Matthew White
Hello, From a general style and/or programmatic perspective, which is a better way to write this bit of code? try: (dn, attrs) = conn.search_s(search_base, search_scope, search_filter, search_attrs): except Exception, e: warn_the_user(e) do_something_useful() for (name,

[Tutor] nested loops

2005-08-22 Thread Jonas Melian
Is there any way more efficient for run a nested loop? -- for a in list_a: for b in list_b: if a == b: break ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] nested loops

2005-08-22 Thread Danny Yoo
On Mon, 22 Aug 2005, Kent Johnson wrote: Is there any way more efficient for run a nested loop? -- for a in list_a: for b in list_b: if a == b: break Hi Jonas, Depends on what we're trying to do. Is it necessary to have a nested loop here? What kind of problem is

Re: [Tutor] while loops

2005-08-08 Thread Will Harris
Thanks for the help guys. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

  1   2   >