[Tutor] syracuse sequence (collatz or hailstone)

2005-10-27 Thread andrade1
Hello I am trying to create a program that will calculate the syracuse sequence which is also known as collatz or hailstone. the number that is input by the user may be either even or odd. the number goes through a series of functions which are x/2 if the number is even and 3x+1 if the number is o

[Tutor] equivalent of 'last' in perl

2005-10-27 Thread Johan Meskens CS3 jmcs3
hi is that if flag == 1: break ? thanks jmcs3 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Can anyone help me?

2005-10-27 Thread Nathan Pinno
If I create a program that randomly draws 6 numbers, its like the lottery. According to an article I read in Reader's Digest, if you get a Quick Pick - which is six numbers at random - you increase your odds of winning. I want to create a program that will imitate the Quick Pick process for myself.

Re: [Tutor] IDLE error msgs and line continuations?

2005-10-27 Thread bob
At 08:06 PM 10/27/2005, Jason Massey wrote: >All you need is the line continuation character, '\': > >if (condition 123 and \ >condition 456) : Did you test that (or even read it)? That is a syntax error line continuation or not! Also recall that the parentheses obviate the need for the \.

[Tutor] Plea for Meaningful Subject Lines (was: Can anyone help me?)

2005-10-27 Thread bob
Please in future provide meaningful subject lines. It makes it a lot easier to track the threads. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Can anyone help me?

2005-10-27 Thread bob
At 07:07 PM 10/27/2005, Nathan Pinno wrote: >Hey all, >I am trying to create a program that draws 6 numbers between 1 and 49 at >random for creating lottery tickets. I want to have a better chance when I >play. Define "better chance". Lottery odds are how many tickets you buy relative to how ma

Re: [Tutor] File IO Help again

2005-10-27 Thread bob
At 01:42 PM 10/27/2005, Adam wrote: > >if line[:1] == "1": > >This line won't work because you're getting the first 2 characters from >the line Oh? Did you test that? When I do that I get 1 character. Why? Because slicing goes UP TO the 2nd argument. >>> 'abc'[:1] 'a'

Re: [Tutor] IDLE error msgs and line continuations?

2005-10-27 Thread Jason Massey
All you need is the line continuation character, '\': if (condition 123 and \ condition 456) : On 10/27/05, CPIM Ronin <[EMAIL PROTECTED]> wrote: > When using IDLE, after hitting F5 to save and run, if an error occurs, it > merely flashes at the code location of the error. While I usually figu

Re: [Tutor] Can anyone help me?

2005-10-27 Thread R. Alan Monroe
> Hey all, > I am trying to create a program that draws 6 numbers between 1 and 49 at > random for creating lottery tickets. I want to have a better chance when I > play. Can anyone help me code this or show me how > to, please? Create (empty for now) list to hold your final numbers. Have a for-

Re: [Tutor] Module Thread

2005-10-27 Thread Kent Johnson
Joseph Quigley wrote: > Hi, thanks for the info. > I'd like o know if you guys know of any good documentation on the > threading module. Or if you could give me a quick intro to it. Or am I > asking too much? If so I'll try to work it out on my own for a little. In truth I am worn out on thread qu

[Tutor] Can anyone help me?

2005-10-27 Thread Nathan Pinno
Hey all, I am trying to create a program that draws 6 numbers between 1 and 49 at random for creating lottery tickets. I want to have a better chance when I play. Can anyone help me code this or show me how to, please? Thanks, Nathan Pinno For great sites go to: http://falcon3166.tripod.comMSN

[Tutor] IDLE error msgs and line continuations?

2005-10-27 Thread CPIM Ronin
When using IDLE, after hitting F5 to save and run, if an error occurs, it merely flashes at the code location of the error. While I usually figure out what is wrong, why don't I get the detailed text error messages that the command line gives? Also, I'm getting most error messages when I try li

Re: [Tutor] os.system sending of break signals

2005-10-27 Thread R. Alan Monroe
>> I send a command to os.system(cmd) and want to send a break signal in >> the same way. Is this possible? The break signal is ctrl c (^c). >> I tried this, but it didn't work: os.system('\x03') I think Hex 03 is >> the signal for ctrl c. > Its not possible with os.system because os.system runs

Re: [Tutor] Weird iteration using zip()

2005-10-27 Thread Alan Gauld
a = ['a','b','c','d','e'] b = [1,2,3,4,5] abdict = dict(zip(a,b)) abdict > {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} > > > Why is this weird iteration going on" Dictionaries store their values in the most efficient way for key lookup they do not store them in order. In fact t

Re: [Tutor] os.system sending of break signals

2005-10-27 Thread Alan Gauld
> I send a command to os.system(cmd) and want to send a break signal in > the same way. Is this possible? The break signal is ctrl c (^c). > I tried this, but it didn't work: os.system('\x03') I think Hex 03 is > the signal for ctrl c. Its not possible with os.system because os.system runs the c

Re: [Tutor] Question about an re

2005-10-27 Thread ->Terry<-
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Today (Oct 27, 2005) at 9:29am, Ed Singleton spoke these wise words: - ->OR tests for the truth of the first thing then the truth of the second. - -> - ->The first part of your OR is always true, so it doesn't test the second. - -> - ->What you reall

Re: [Tutor] Module Thread

2005-10-27 Thread Joseph Quigley
Hi, thanks for the info. I'd like o know if you guys know of any good documentation on the threading module. Or if you could give me a quick intro to it. Or am I asking too much? If so I'll try to work it out on my own for a little. ___ Tutor maillist -

Re: [Tutor] File IO Help again

2005-10-27 Thread Adam
>if line[:1] == "1": This line won't work because you're getting the first 2 characters from the line and seeing if it's equal to a string of length one. For example in your test file if you put this line, 1      12.4    12.0    *   10 , through that bit of code it would see if "1 " == "1", which

Re: [Tutor] File IO Help again

2005-10-27 Thread bob
At 12:18 PM 10/27/2005, Mike Haft wrote: >Apologies for not making things clearer last time. > >My specific problems are: > >why can I not get the readline() or readlines() functions to work, I'm >told they are not defined whenever I try. Mike * Oh * Mike ... and all others ... Please Post The Co

Re: [Tutor] File IO Help again

2005-10-27 Thread Danny Yoo
On Thu, 27 Oct 2005, Mike Haft wrote: > why can I not get the readline() or readlines() functions to work, I'm > told they are not defined whenever I try. Don't paraphrase. *grin* Show us what you did in terms of the code that you ran. Also, include the literal error message and its tracebac

[Tutor] File IO Help again

2005-10-27 Thread Mike Haft
Apologies for not making things clearer last time. My specific problems are: why can I not get the readline() or readlines() functions to work, I'm told they are not defined whenever I try. Also the following: if line[:1] == "1": collects data from month 1, 10, 11, and 12. How do I make the re

Re: [Tutor] os.system sending of break signals

2005-10-27 Thread Hugo González Monteverde
Even if you could send a break signal, it would go to a new shell that os.system() invokes... Perhaps you know or can get the ID of the process you want to signal, a ctrl-c in a shell is equivalent to a SIGINT sent using os.kill() Please anyone in the list correct me if there is something I mis

Re: [Tutor] Passing Functions or Code as Parameters

2005-10-27 Thread Kent Johnson
Ed Singleton wrote: > Wow, thanks again, Kent. > > If my understanding of functions in Python is correct, then the > do_something() function won't have access to the variables inside > traverse. Is this right? Yes, that's right. Python is lexically scoped which means you have access to variable

Re: [Tutor] Weird iteration using zip()

2005-10-27 Thread Kent Johnson
Srinivas Iyyer wrote: > Hi all: > > Here is a simple code: > > a = ['a','b','c','d','e'] b = [1,2,3,4,5] abdict = dict(zip(a,b)) abdict > > {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} > > > Why is this weird iteration going on" The order of keys in a dict is effectively indeterm

[Tutor] Weird iteration using zip()

2005-10-27 Thread Srinivas Iyyer
Hi all: Here is a simple code: >>> a = ['a','b','c','d','e'] >>> b = [1,2,3,4,5] >>> abdict = dict(zip(a,b)) >>> abdict {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} Why is this weird iteration going on" Why not: >>> abdict {'a':1,'b':2,'c':3,'d':4,'e':5} Is there any hidden logic in the code that

[Tutor] os.system sending of break signals

2005-10-27 Thread Johan Geldenhuys
Hi all, I send a command to os.system(cmd) and want to send a break signal in the same way. Is this possible? The break signal is ctrl c (^c). I tried this, but it didn't work: os.system('\x03') I think Hex 03 is the signal for ctrl c. Thanks, ___ Tu

Re: [Tutor] new user question about while loops

2005-10-27 Thread Danny Yoo
> #assigning variables to track the amount of times heads or tails comes up > heads=0 > tails=1 > > AG> Why not make both zero, after all there have been no flips so far! Hi Alan, There is confusion here about the role of these variables. Despite what the comment says, I assume that 'heads' and

Re: [Tutor] Passing Functions or Code as Parameters

2005-10-27 Thread Kent Johnson
Ed Singleton wrote: > How can I pass a block of code to a function for it to perform within itself? > > For example, I wrote a small function that recurses through a > directory structure but keeps a track of the depth: > > What I want to do is something like: > > from path import path > > def

[Tutor] Passing Functions or Code as Parameters

2005-10-27 Thread Ed Singleton
How can I pass a block of code to a function for it to perform within itself? For example, I wrote a small function that recurses through a directory structure but keeps a track of the depth: from path import path def traverse(directory, depth=0): thedir = path(directory) for item in the

Re: [Tutor] question about try & except

2005-10-27 Thread Kent Johnson
w chun wrote: > if your app is willing to tolerate errors/crashes, then i would take > alan's advice and just letting the errors happen, as opposed to being > so careful with (and integrating Kent's suggestion for the full > traceback with): > > try: > BLOCK > except Exception, e: > print

Re: [Tutor] question about try & except

2005-10-27 Thread w chun
On 10/26/05, nephish <[EMAIL PROTECTED]> wrote: > Yeah, cool. i am just starting this part. > i am glad i started with python. > thanks for the help if your app is willing to tolerate errors/crashes, then i would take alan's advice and just letting the errors happen, as opposed to being so carefu

Re: [Tutor] General programming questions

2005-10-27 Thread w chun
On 10/27/05, Matt Williams <[EMAIL PROTECTED]> wrote: > At the moment, I have something like: > > def __init__ (self, a, b, c): > if type(a) == type("a") > then. > elif type(a) == type(["a"]) > then > > I'm sure there must be a better way to do this

Re: [Tutor] Module Thread

2005-10-27 Thread w chun
On 10/26/05, Joseph Quigley <[EMAIL PROTECTED]> wrote: > I'm back to my IRC client. I accidentally found the thread module... > What will i do to receive and send at the same time via console? > > or: > Should I forget the idea of a console and start learning GUI which > will > do

Re: [Tutor] General programming questions

2005-10-27 Thread Alan Gauld
> 1: I need to create objects that have variable levels of behaviour > (controlled perhaps by a .config file). I can do the file reading, etc. > - but how do I implement the behaviour, apart from just re-writing all > the functions for each config level? Usually by having multiple subclasses and i

Re: [Tutor] Module Thread

2005-10-27 Thread Kent Johnson
Joseph Quigley wrote: > I'm back to my IRC client. I accidentally found the thread module in the > Python 2.3 documentation while looking at the time module. Wow, threads are in the air this month! You should use the threading module, not thread. threading is higher-level and more capable. Take a

Re: [Tutor] question about try & except

2005-10-27 Thread Kent Johnson
nephish wrote: > Hey there, > i am writing some (for me) pretty complicated stuff for work that > really needs to work. > i have looked at exception handling in the Learning Python book. > and i am using some try / except statements. > the problem is, that even though my script

Re: [Tutor] Question about an re

2005-10-27 Thread Ed Singleton
OR tests for the truth of the first thing then the truth of the second. The first part of your OR is always true, so it doesn't test the second. What you really want to do is look for a digit and then look for more digits or a slash and some more digits. So: : \d(\d+|/\d+) but this is easier b

Re: [Tutor] question about try & except

2005-10-27 Thread Alan Gauld
> and i am using some try / except statements. > the problem is, that even though my script does not crash, i dont know > the exact error. IT sounds like your try/except is masking the error. Its usually a good idea to NOT Use try/except when developing your code, then go back and put it in whe

[Tutor] General programming questions

2005-10-27 Thread Matt Williams
Dear List, I've got a few general programming (not really specific to python, although you're all so helpful, I thought I'd ask here). I understand some of these are a bit long, so if you could just point me to some resources, I'd be very grateful. 1: I need to create objects that have variable l