Re: [Tutor] square root

2007-05-27 Thread Norman Khine
Hello,
I have not seen your radiacir.py programme so I am not sure what you
want, but for square root, try this
http://mail.python.org/pipermail/tutor/2001-February/003411.html

HTH

adam urbas wrote:
> Hi all,
> 
> I was just wondering how I would go about performing a square root
> thing, for my radiacir.py program.
> 
> 
> Create the ultimate e-mail address book. Import your contacts to Windows
> Live Hotmail. Try it!
> 
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Norman


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


Re: [Tutor] square root

2007-05-27 Thread John Fouhy
Check out the math module.

On 28/05/07, adam urbas <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> I was just wondering how I would go about performing a square root thing,
> for my radiacir.py program.
>
> 
> Create the ultimate e-mail address book. Import your contacts to Windows
> Live Hotmail. Try it!
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] square root

2007-05-27 Thread adam urbas
Hi all,I was just wondering how I would go about performing a square root 
thing, for my radiacir.py program.
_
Change is good. See what’s different about Windows Live Hotmail.
www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_changegood_0507___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with "if"

2007-05-27 Thread adam urbas
I thank you much Alan.  This has been very helpful already and I'm only on page 
2.  The world needs more newb-friendly people like you.> To: tutor@python.org> 
From: [EMAIL PROTECTED]> Date: Thu, 24 May 2007 23:39:41 +0100> Subject: Re: 
[Tutor] trouble with "if"> > 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
_
Download Messenger. Start an i’m conversation. Support a cause. Join now.
http://im.live.com/messenger/im/home/?source=TAGWL_MAY07___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with indents

2007-05-27 Thread Bob Gailer




adam urbas wrote:

  
  Thanks for the clarification, but I'm
still a tad confused.  I'm not sure when to indent.  

The following keywords introduce a "suite" (1 or more statements) that
are "controlled" by the keyword. Those statements must be indented
further than the keyword. What more can anyone say? If this is not
clear please explain at which point you lose clarity.
 if
 elif
 else
 while
 for 
 try
 except
 finally
 with 
 def 
 class

Example:
 a = 0
 while a < 4: # statement that introduces a suite
    print a   # another statement in the while suite
    if a == 2: # statement in the while that introduces
another suite
    print "We hit 2" # statement in the if suite
    a += 1    # statement in the while suite;
if suite has ended
 print "done" # while suite has ended

This results in output:
0
1
2
We hit 2
3

-- 
Bob Gailer
510-978-4454


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


Re: [Tutor] trouble with "if"

2007-05-27 Thread adam urbas
You don't know what a Ti 83 is.  Calculator.  The most basic programming 
available.  It already has so many functions built into it that it is much 
easier to tell it to do things.  You don't have to do all this integer 
conversion and such whatnot.  Wow... I'm really unsure of how this thing is 
supposed to work.  It seems the more I learn about Python, the more confused I 
become.  It's enough to bring tears to your eyes.  Not really but ya.Someone 
else helped me with the problem of accepting numbers and words.  I used:if 
shape in["1","circle"]:something like that.  It works wonderfully.  I'm not 
sure why, but I know that it does and that is enough.  Someone else also said 
that I had to convert to int, and I did.  That was another problem, which is 
now fixed.But, as usual, it is just one problem after another.  Now I have run 
into this error message: Traceback (most recent call last):  File "C:\Documents 
and Settings\HP_Owner\Python0\area.py", line 23, in area = 
3.14*(radius**2)TypeError: unsupported operand type(s) for ** or pow(): 'str' 
and 'int'>>> and others like this:Traceback (most recent call last):  File 
"C:\Documents and Settings\HP_Owner\Python0\area.py", line 19, in 
area = height*widthTypeError: can't multiply sequence by non-int of type 
'str'>>> Very frustrating.  What is a non-int and what is 'str'?  Why can't it 
multiply the sequence?  I guess I should include the program I'm using for 
these things.I'm having this problem with both of these attached.  The messages 
above are from area.py.  area.py is sort of a prototype of radiacir.py, a test 
version.  You know, I should probably try that int trick, which I seem to have 
forgotten.  And guess what that did it.  It's amazing when you apply the things 
that you learn.  Apparently  I am quite absent minded.  Well It seems I don't 
need any of this help anymore.  Oh well.  Thanks anyway.Au > To: 
tutor@python.org> From: [EMAIL PROTECTED]> Date: Thu, 24 May 2007 23:34:05 
+0100> Subject: Re: [Tutor] trouble with "if"> > "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
_
Create the ultimate e-mail address book. Import your contacts to Windows Live 
Hotmail.
www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507#"Area calculation program"

print "Welcome to the Area calculation program"
print "–"
print

# "Print out the menu:"
print "Please select a shape:"
print "1,  Rectangle"
print "2,  Circle"

#"Get the user’s choice:"
shape = raw_input("> ")

#"Calculate the area:"
if shape in["1","rectangle"]:
height = raw_input("Please enter the height: ")
width = raw_input("Please enter the width: ")
area = height*width
print "The area is", area
if shape in["2","circle"]:
radius = raw_input("Please enter the radius: ")
area = 3.14*(radius**2)
print "The area is", area
#"Circle Data Calculation Program:"
print "Welcome to the Circle Data Calcuation Program."
print

#"Menu 1:"
print "Pick a shape:"
print "(NOTE: You must select the number of the shape and not the shape itself)"
print "1 Circle"
print "2 Square"
print "3 Triangle"

#"User's Choice:"
shape=raw_input("> ")

#"Select Given:"
if shape == "1" or shape == "circle":
print "Choose the given value:"
print "1 radius"
print "2 diameter"
print "3 circumference"
print "4 area"

#"User's Choice:"
given=raw_input("> ")

if given in["1", "radius"]:
radius=raw_input("Enter Radius:")
pi=3.14
diameter=(radius*2)
circumference=(radius*2*pi)
area=(radius**2*3.14)
print "Diameter:", diameter
print "Circumference:", circumference
print "Area:", area

if given == 2:
diameter=raw_input("Enter Diameter:")
radius=(diameter/2)
circumference=(diameter*3.14)
area=(radius**2*3.14)
print "Radius:", radius
print "Circumference:", circumference
print "Area:", are

Re: [Tutor] trouble with indents

2007-05-27 Thread Brian van den Broek
adam urbas said unto the world upon 05/28/2007 12:24 AM:
> Thanks for the clarification, but I'm still a tad confused.  I'm
> not sure when to indent.  I understand that it has to be done.
> That link was really confusing.  Very newb non-friendly.  Arrg...
> That site is doom.  So confusing.  I need somewhere to start from
> the beginning.  This site uses all kinds of big words and doesn't
> explain things in a clear manner.  Oh well.  Thanks for the help,
> though.Au> From: [EMAIL PROTECTED]> To: tutor@python.org> Date:
> Thu, 24 May 2007 15:30:34 -0400> Subject: Re: [Tutor] trouble with
> if> > >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>



Adam,

I think Dive Into Python is quite good, but as a second book or a 
first book for someone with a bit more experience of other languages 
than it seems like you might have.

The first think I read was  
which is aimed at high school students. It might move a bit slowly for 
some tastes, but it sounds like DIP is moving a bit too fast. The full 
text is free; give it a look.

Best,

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


Re: [Tutor] trouble with indents

2007-05-27 Thread adam urbas
Thanks for the clarification, but I'm still a tad confused.  I'm not sure when 
to indent.  I understand that it has to be done.  That link was really 
confusing.  Very newb non-friendly.  Arrg... That site is doom.  So confusing.  
I need somewhere to start from the beginning.  This site uses all kinds of big 
words and doesn't explain things in a clear manner.  Oh well.  Thanks for the 
help, though.Au> From: [EMAIL PROTECTED]> To: tutor@python.org> Date: Thu, 24 
May 2007 15:30:34 -0400> Subject: Re: [Tutor] trouble with if> > >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>
 
_
Create the ultimate e-mail address book. Import your contacts to Windows Live 
Hotmail.
www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] numbers and ranges

2007-05-27 Thread Kent Johnson
Jon Crump wrote:
> Kent,
> 
> That's damned clever! Your solution hovers right at the limit of my 
> understanding, but the print statements illustrate very clearly the 
> operation of the function.

You're welcome! I recently wrote some notes about iterators and 
generators that might help your understanding:
http://personalpages.tds.net/~kent37/kk/4.html

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


Re: [Tutor] numbers and ranges

2007-05-27 Thread Jon Crump
Kent,

That's damned clever! Your solution hovers right at the limit of my 
understanding, but the print statements illustrate very clearly the 
operation of the function.

Many thanks!
Jon

On Sun, 27 May 2007, Kent Johnson wrote:
>> Here's a puzzle that should be simple, but I'm so used to words that 
>> numbers tend to baffle me.
>> 
>> I've got fields that look something like this:
>> 1942. Oct. 1,3,5,7,8,9,10
>> 
>> I need to parse them to obtain something like this:
>> 
>> 
>> 
>> 
>
> Here is a solution that uses a generator to create the ranges:
>
> def ranges(data):
>i = iter(data)
>first = last = i.next()
>try:
>while 1:
>next = i.next()
>if next > last+1:
>yield (first, last)
>first = last = next
>else:
>last = next
>except StopIteration:
>yield (first, last)
>
> print list(ranges((1,)))
> print list(ranges((1,2,3)))
> print list(ranges((1,3,5)))
> print list(ranges((1,3,5,7,8,9,10)))
>
> for start, end in ranges((1,3,5,7,8,9,10)):
>if start == end:
>print '' % start
>else:
>print '' % (start, 
> end)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] numbers and ranges

2007-05-27 Thread Kent Johnson
Jon Crump wrote:
> Dear all,
> 
> Here's a puzzle that should be simple, but I'm so used to words that 
> numbers tend to baffle me.
> 
> I've got fields that look something like this:
> 1942. Oct. 1,3,5,7,8,9,10
> 
> I need to parse them to obtain something like this:
> 
> 
> 
> 
> 
> The xml representation is incidental, the basic problem is how to test a 
> list of integers to see if they contain a range, and if they do, do 
> something different with them.

Here is a solution that uses a generator to create the ranges:

def ranges(data):
 i = iter(data)
 first = last = i.next()
 try:
 while 1:
 next = i.next()
 if next > last+1:
 yield (first, last)
 first = last = next
 else:
 last = next
 except StopIteration:
 yield (first, last)

print list(ranges((1,)))
print list(ranges((1,2,3)))
print list(ranges((1,3,5)))
print list(ranges((1,3,5,7,8,9,10)))

for start, end in ranges((1,3,5,7,8,9,10)):
 if start == end:
 print '' % start
 else:
 print '' % 
(start, end)


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


Re: [Tutor] numbers and ranges

2007-05-27 Thread Bob Gailer
Jon Crump wrote:
> Dear all,
>
> Here's a puzzle that should be simple, but I'm so used to words that 
> numbers tend to baffle me.
>
> I've got fields that look something like this:
> 1942. Oct. 1,3,5,7,8,9,10
>
> I need to parse them to obtain something like this:
> 
> 
> 
> 
>
> The xml representation is incidental, the basic problem is how to test a 
> list of integers to see if they contain a range, and if they do, do 
> something different with them.
>   
numList = (1, 3, 5, 7, 8, 9, 10)
inSequence = False
result = ""
priorNumber = numList[0]
for number in numList[1:]:
  if number - priorNumber == 1:
if not inSequence:
  seqStart = priorNumber
  inSequence = True
  else:
if inSequence:
  result += '\n' % 
(seqStart, priorNumber)
  inSequence = False
else:
  result += '\n' % priorNumber
  priorNumber = number
if inSequence:
  result += '\n' % 
(seqStart, priorNumber)
print result
> I'm sure this is the question of a rank tyro, but the denizens of this 
> list seem tolerant and gentle. Many thanks.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   


-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] trouble with "if"

2007-05-27 Thread Brian van den Broek
adam urbas said unto the world upon 05/27/2007 01:49 PM:
> Thank you for the help Brian.  I would like to ask you about these
> things.  Which one of the examples you gave would be most fool
> proof.




Hi Adam and all,

Adam was asking about how to use raw_input to drive a basic command 
prompt menu system. I'd tried to explain that raw_input returns 
strings, so his if tests which were something like:

choice = raw_input("Enter an option)
if choice == 1:
 do_option_1_stuff()
elif choice == 2:
 do_option_2_stuff()

were not going to work, as choice will never be equal to an int.

I'd sketched a few ways to deal with this, chiefly applying int() to 
choice or comparing choice to '1', etc.

That's more of less the gist of the above snippage and takes us more 
or less up to the point where Adam asked his question above.

I'm going to show you a few things that might be new to you, Adam. 
Let's build up in steps.

As a first pass, I would do the following:

choice = int(raw_input("Please make your choice "))

if choice == 1:
 # Option 1 code here
 print "In option 1"

elif choice == 2:
 # Option 2 code here
 print "In option 2"

# Carry on if-test as needed (or until you get to the point
# of learning about dictionary dispatch :-)

That will be fine, until your user enters something silly:

 >>>
Please make your choice I like bikes!
Traceback (most recent call last):
   File "/home/brian/docs/jotter/python_scraps/adamcode.py", line 1, 
in 
 choice = int(raw_input("Please make your choice "))
ValueError: invalid literal for int() with base 10: 'I like bikes!'
 >>>

That's no good!

So, we can use Python's exception handling tools to make this a bit 
better.


try:
 choice = int(raw_input("Please make your choice "))
except ValueError:
 print "Please make a choice from the options offered."


if choice == 1:
 print "In option 1"

elif choice == 2:
 print "In option 2"


There is still a problem, though:

 >>> # Make sure the previous value assigned to choice is gone.
 >>> del(choice)
 >>>
Please make your choice I like Bikes
Please make a choice from the options offered.
Traceback (most recent call last):
   File "/home/brian/docs/jotter/python_scraps/adamcode.py", line 7, 
in 
 if choice == 1:
NameError: name 'choice' is not defined
 >>>

We've printed the reminder to the user, but then have gone on to 
compare the non-existent choice value to 1, and that doesn't work so 
well. It isn't enough to make sure that choice isn't insane---we need 
to make sure that there is a choice value at all.

So, better still:


while True:
 try:
 choice = int(raw_input("Please make your choice "))
 # If the previous line worked, end the while loop. If it did
 # not work, we won't get here, so the loop will keep looping.
 break
 except ValueError:
 print "Please make a choice from the options offered."

if choice == 1:
 print "In option 1"

elif choice == 2:
 print "In option 2"


Now we get the following:

Please make your choice I like bikes!
Please make a choice from the options offered.
Please make your choice Please take this
Please make a choice from the options offered.
Please make your choice1
In option 1
 >>>


There is still a problem, though:

Please make your choice 42
 >>>

Our sanity check has only insisted that the user enter a value that 
can be turned into an int; nothing as yet makes it be one of the ints 
we are expecting.

So, try this:

while True:
 try:
 choice = int(raw_input("Please make your choice "))
 if choice < 1 or choice > 2: # Adjust to suit options
 raise ValueError
 break
 except ValueError:
 print "Please make a choice from the options offered."

if choice == 1:
 print "In option 1"

elif choice == 2:
 print "In option 2"


Please make your choice I like bikes!
Please make a choice from the options offered.
Please make your choice 42
Please make a choice from the options offered.
Please make your choice 2
In option 2
 >>>


Now, all of this should be formatted to be a bit prettier---and 
displaying the allowable options up front is a good idea, too---but 
the essential ideas are there.

There might be some parts of this that are new to you, so ask away if 
you've gotten a bit lost.

And, I'm no expert, so if someone else comes along and says `No, don't 
do it like that', odds are they might be right. (Especially if their 
name is Alan, Danny, or Kent ;-)

Best,

Brian vdB

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


Re: [Tutor] error message questions

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

> Hello all,I was wondering if there would be someone who
> would be able to give me a list of error messages and
> their meanings.

The errors are actually self explanatory - no really! - once
you undestandd the basic concepts. But to understand
those you will need to go back to basics.

I suggested in an earlier post that you read my Raw Materials topic
which discusses data and types. Did you do that?

Also the Talking to the User illustrates the use of raw_input,
you could usefully read that too. it discusses using the Python
conversion functions to get the right input values from raw_input..

> It says:can't multiply sequence by non-int of type 'str'

Which means Python cannot multiply the two types of data
you are giving it. You need to convert those values to the compatible
types.

> can't multiply sequence by non-int of type 'float'

Same thing, you have a sequence type on one side
(probably a string but could be a list or tuple?) and a float
on the other. You need to turn the sequence into something
that a float can multiply - either another float or an int (or
a complex or decimal if you feel really picky).

-- 
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] numbers and ranges

2007-05-27 Thread Jon Crump
Dear all,

Here's a puzzle that should be simple, but I'm so used to words that 
numbers tend to baffle me.

I've got fields that look something like this:
1942. Oct. 1,3,5,7,8,9,10

I need to parse them to obtain something like this:





The xml representation is incidental, the basic problem is how to test a 
list of integers to see if they contain a range, and if they do, do 
something different with them.

I'm sure this is the question of a rank tyro, but the denizens of this 
list seem tolerant and gentle. Many thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message questions

2007-05-27 Thread Rikard Bosnjakovic
On 5/27/07, adam urbas <[EMAIL PROTECTED]> wrote:

> It says:
>
> can't multiply sequence by non-int of type 'str'

The reason is that raw_input() returns a string. What you are trying
to do is multiply a string with a string, which - in Python - is an
illegal operation.

What you want to do is to convert the read value from raw_input() to
an integer, and then multiply. You convert with the function int(). So
if you change the two upper lines of your code test.py to

height = int(raw_input("enter height:"))
width = int(raw_input("enter width:"))

then the multiplication will work. It will - however - not work if you
don't enter a numerical value, because int() will fail for everything
else than numericals.

HTH.


-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with "if"

2007-05-27 Thread adam urbas
Thank you for the help Brian.  I would like to ask you about these things.  
Which one of the examples you gave would be most fool proof.> Date: Wed, 23 May 
2007 13:40:09 -0400> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: 
tutor@python.org> Subject: Re: [Tutor] trouble with "if"> > adam urbas said 
unto the world upon 05/23/2007 01:04 PM:> > Sorry, I don't think Hotmail has 
turn off HTML.  If it does I> > havn't been able to find it.  I think you're 
going to have to> > explain your little bit of text stuff down there at the 
bottom.  I> > have no idea what most of that means.  All my choice things are> 
> working now though.  I think that is what you were trying to help> > me with. 
 What I used wasif shape in["1","circle"]:and if shape ==> > "1" or shape 
=="circle":It works perfectly fine now.Ya that little> > bit o' code is really 
puzzling.  I wish I knew more about this> > python deal.  I understand the 
concept, but not the rules or the> > techniques and things of that sort.  OK... 
I've got it... the> > data=raw_input('Feed Me!').  Ok I now understand that 
bit.  Then it> > says Feed Me!  and you put 42 (the ultimate answer to life 
the> > universe, everything).  OK, it won't accept the  bit.> > it 
doesn't like the "<".  Well, I just removed that bit and it> > said:Feed Me!  
and I put 42, and it said >>> (I guess it's> > satisfied now, with the whole 
feeding).  Well if I understood what> > 'str' meant, then I could probably 
figure the rest out.  Well I> > have to go do other things so I'll save the 
rest of this figuring> > out till later.I shall return,Adam> Date: Wed, 23 May 
2007 12:12:16> > -0400> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC:> > 
tutor@python.org> Subject: Re: [Tutor] trouble with "if"> > adam> > urbas said 
unto the world upon 05/23/2007 11:57 AM:> > > > Hi all,>> > > > > I've been 
working with this new program that I wrote.  I> > started out > > with it on a 
Ti-83, which is much easier to program> > than python.  Now > > I'm trying to 
transfer the program to python> > but its proving to be quite > > difficult.  
I'm not sure what the> > whole indentation thing is for.  And > > now I'm 
having trouble> > with the if statement things. > > > > #"Circle Data 
Calculation> > Program:"> > print "Welcome to the Circle Data Calcuation> > 
Program."> > print> > > > #"Menu 1:"> > print "Pick a shape:">> > > print 
"(NOTE: You must select the number of the shape and not the> > shape > > 
itself)"> > print "1 Circle"> > print "2 Square"> > print> > "3 Triangle"> > > 
> #"User's Choice:"> > shape=raw_input("> ")>> > > > > #"Select 
Given:"> > if shape == 1:> > print> > "Choose the given value:"> >  
   print "1 radius"> >> > print "2 diameter"> > print "3 
circumference"> >> > print "4 area"> > > > #"User's Choice:"> > 
given=raw_input("> ")> >> > > > if given == 1:> > 
radius=raw_input("Enter Radius:")> >> > diameter=(radius*2)> > 
circumference=(diameter*3.14)> >> > area=(radius**2*3.14)> > print 
"Diameter:", diameter> >> > print "Circumference:", circumference> > 
print "Area:",> > area> > > > if given == 2:> > 
diameter=raw_input("Enter> > Diameter:")> > radius=(diameter/2)> >> > 
circumference=(diameter*3.14)> > area=(radius**2*3.14)> >> > print 
"Radius:", radius> > print "Circumference:",> > circumference> >
 print "Area:", area> > > > if given == 3:>> > > 
circumference=raw_input("Enter Circumference:")> >> > 
radius=(circumference/3.14/2)> > diameter=(radius*2)> >> > 
area=(radius**2*3.14)> > print "Radius:", radius> >> > print 
"Diameter:", diameter> > print "Area:", area> > > >> > if given == 4:> 
> area=raw_input("Enter Area:")> >> > radius=(area/3.14)> >  > 
> This is the whole program so> > far, because I haven't quite finished it > > 
yet.  But I tried to> > get it to display another list of options after you > > 
select a> > shape but it just does this.> > > > Pick a shape:> > 1 Circle> > 2> 
> Square> > 3 Triangle> >  >1> >  >1> >   > > > I'm not sure why> > it does 
that but I do know that it is skipping the > > second list> > of options.> > > 
> Another of my problems is that I can't figure> > out how to get it to > > 
accept two different inputs for a> > selection.  Like I want it to accept > > 
both the number 1 and> > circle as circle then list the options for > > circle. 
 It won't> > even accept words.  I can only get it to accept > > numbers.  
It's> > quite frustrating actually.> > > > Any advice would be greatly> > 
appreciated.> > Thanks in advance,> > Adam> > > > > > > Adam,> >> > Could you 
send plain text email rather than html, please? At least> > for > me, your 
code's indentation is all messed up unless I take> > some steps > to rectify 
it.> > The problem is that raw_input> > returns a string, and you are testing > 
whether given is equal to> > integers. See if this helps m

[Tutor] error message questions

2007-05-27 Thread adam urbas
Hello all,I was wondering if there would be someone who would be able to give 
me a list of error messages and their meanings.  I've attached this test.py to 
illustrate my problem.  When I run the program, I am able to enter all the 
data, yet it will not calculate.It says:can't multiply sequence by non-int of 
type 'str'I really would like to know how to fix this.I get a similar message 
with my other one, radiacir.py:can't multiply sequence by non-int of type 
'float'Please help!Thanks in advance,Adam
_
Change is good. See what’s different about Windows Live Hotmail. 
http://www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=RMT_TAGLM_HMWL_reten_changegood_0507
height=raw_input("enter height:")
width=raw_input("enter width:")

area=(height*width)

print "area:",area
#"Circle Data Calculation Program:"
print "Welcome to the Circle Data Calcuation Program."
print

#"Menu 1:"
print "Pick a shape:"
print "(NOTE: You must select the number of the shape and not the shape itself)"
print "1 Circle"
print "2 Square"
print "3 Triangle"

#"User's Choice:"
shape=raw_input("> ")

#"Select Given:"
if shape == "1" or shape == "circle":
print "Choose the given value:"
print "1 radius"
print "2 diameter"
print "3 circumference"
print "4 area"

#"User's Choice:"
given=raw_input("> ")

if given in["1", "radius"]:
radius=raw_input("Enter Radius:")
pi=3.14
diameter=(radius*2)
circumference=(radius*2*pi)
area=(radius**2*3.14)
print "Diameter:", diameter
print "Circumference:", circumference
print "Area:", area

if given == 2:
diameter=raw_input("Enter Diameter:")
radius=(diameter/2)
circumference=(diameter*3.14)
area=(radius**2*3.14)
print "Radius:", radius
print "Circumference:", circumference
print "Area:", area

if given == 3:
circumference=raw_input("Enter Circumference:")
radius=(circumference/3.14/2)
diameter=(radius*2)
area=(radius**2*3.14)
print "Radius:", radius
print "Diameter:", diameter
print "Area:", area

if given == 4:
area=raw_input("Enter Area:")
radius=(area/3.14)
  


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


Re: [Tutor] monitor other running applications with Python?

2007-05-27 Thread Alan Gauld
"Che M" <[EMAIL PROTECTED]> wrote

> Hi, searched a bit for this but haven't found much.  
> Is it possible to use Python to monitor the use of 
> other applications? 

Yes, definitely.

> At minimum, I wan't to know that the application was running

Thats fairly easy using OS tools such as ps on Unix.
You can dig a little deeper and use the system APIs such 
as the proc fiilesystem or the equivalent in the windows 
registry.

> better would be some sense of the use or content, such 
> as whether the app was idle or the user was using it, 
> or, for a web browser, what URLs were visited and for 
> how long, etc.  

Thats possible but gets very OS specific and very low level too.
On Windows you can catch Windows events and messages 
using some of the raw Win32 API calls from the ctypes module.
(I've never used ctypes for anything this low level but it 
should be possible, I''ve certainly done it in C++ and Delphi
on Win 9X). But its messy and fairly deep Windows magic 
and you will need to spend a fair bit of time experimenting 
and reading the docs on MSDN as well as the Win32 API 
help file.

> Ideally I'd like a cross-platforms approach 

I doubt if that's possible except at the process monitoring 
level. For the kind of detail you want the bgestb you can 
do is have a common UI and pluggable modules based 
on the OS.

Also beware legal implications. There are issues around 
personal privacy, data proptection etc and these vary between 
countries (and even states in the US). People are increasingly 
wary of Big Brother style monitoring. Detecting inappropriate 
use of the internet across a corporate firwall is generally 
considered OK but silently monitoring individuals brings you 
into murky legal waters.

Finally, take a look at the stuff in the os package and the 
syslog module for Unix. 

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