Re: [Tutor] trouble with if

2007-05-24 Thread Che M
I'm not sure what the whole indentation thing is for.  And now I'm having 
trouble with the if statement things.


Maybe your if statement troubles have been solved by others by now, but I'll 
just add that "the indentation thing" is a vital feature of Python, it is 
the way to separate code blocks.  Other languages uses other means, like 
curly braces, etc.  I get the sense those who like Python enjoy indentation 
because it forces the code to be quite readable, and I agree.  See this:


http://www.diveintopython.org/getting_to_know_python/indenting_code.html

Also, as mentioned previously, keep in mind that 2 is not the same as "2" 
and "=" is not the same as "==".  The single "=" is used to assign names to 
objects, whereas the == is for evaluating something, so for if statements 
use == and not =.  Also note you can put "and" along with if, so you can say


if x == "mom" and y == "dad":
   print "my parents"

and lots of other stuff.
-Che

_
PC Magazine’s 2007 editors’ choice for best Web mail—award-winning Windows 
Live Hotmail. 
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with "if"

2007-05-24 Thread Alan Gauld
"adam urbas" <[EMAIL PROTECTED]> wrote 

>  It won't even accept words.  
> I can only get it to accept numbers.  

try this(untested code!):

number = None
data = raw_input('Type something: ')
try: number = int(data)
except: data = data.split()# assume a string

if number:# user entered a number
if number == 1:  print 'circle'
elif number == 2: print 'another'
else: # user entered words
if data[0].lower() == 'circle': print 'circle'
else: print 'user entered ', data[0]

Notice that to use ithe input as a number you have to 
convert the raw input characters to a number (using int)
To get the individual words we can use split() which by 
default splits a string into the individual words.

Is that the kind of thing you mean?

I've no idea what a Ti83 is BTW. :-)

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with "if"

2007-05-24 Thread Alan Gauld
Hi adam. 

With the aid of Google it seems a Ti83 is a programmable calculator.

I'm not sure what python tutor you are using but it looks like 
you need to cover some very basic stuff around data types.

You may find the Raw Materials topic in my tutor useful to give 
you a feel for the different types of data in Python.

The Talking to the User topic will cover the use of raw_input.

And the Branching topic has an examplre very similar to what 
you are trying to do.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tkinter arrow event location

2007-05-24 Thread Alan Gauld

"Teresa Stanton" <[EMAIL PROTECTED]> wrote
> Using a mouse I could use event.x to find the current location of 
> the mouse.
> But if I have a canvas with a gif and I need the current location of 
> the
> gif, could I bind the gif to an arrow event to get the feedback of 
> where the
> gif is at any given time? If so, can someone show me how?

If you mean an arrow key then yes you can trap keystrokes
and the event driven programming topic of my tutor shows
how to do that in Tkinter.

Once you've detected the keys that you want you should be
able to ask the canvas where the gif currently is located.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] dealing with nested list values in a dictionary

2007-05-24 Thread kumar s
Dear group,

unfortunately my previous post got tagged as
'homework' mail and got no responses. 

In short, I have a dictionary structure as depicted
below. 

I want to go over every key and print the key,value
pairs in a more sensible way. 

I have written a small piece of code. May I request
tutors to go through it and comment if it is correct
or prone to bugs. 

Thank you. 
kum

>>>md = {(21597133, 21597325): [['NM_032457']], 
(21399193, 21399334): [['NM_032456'], ['NM_002589']], 
(21397395, 21399192): [['NM_032457'], ['NM_032456'],
['NM_002589']], 
(21407733, 21408196): [['NM_002589']], 
(21401577, 21402315): [['NM_032456']], 
(21819453, 21820111): [['NM_032457']], 
(21399335, 21401576): [['NM_032457'], ['NM_032456'],
['NM_002589']]}

>>> for item in md.keys():
mlst = []
for frnd in md[item]:
for srnd in frnd:
mlst.append(srnd)
mystr = ','.join(mlst)
print(('%d\t%d\t%s')%(item[0],item[1],mystr))


2159713321597325NM_032457
2139919321399334NM_032456,NM_002589
2139739521399192NM_032457,NM_032456,NM_002589
2140773321408196NM_002589
2140157721402315NM_032456
2181945321820111NM_032457
2139933521401576NM_032457,NM_032456,NM_002589


  
Fussy?
 Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay 
it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor