[Tutor] (no subject)

Gregor Lingl glingl@aon.at
Tue, 25 Dec 2001 09:39:09 +0100


----- Original Message -----
From: "Kirk Bailey" <deliberatus@my995internet.com>
To: "Iain Long" <ilflexi2@hotmail.com>
Cc: <tutor@python.org>
Sent: Tuesday, December 25, 2001 12:12 AM
Subject: Re: [Tutor] (no subject)

Unfortunately there are several flaws
concerning sytax as well as logic
in the code below, so it will not work:


> WEll, try this:
>
> def square(x)
> x*x

1. firsdt line needs an ":" at the end
2. second line has to be idented
3. This line will return  the special object
   None instead of the desired square of x
   Therefore the codeline in areacircle
   will raise an error

Correctly it should read:

def square(x):
    return x*x

>
> Then, try this:
>
> pi = 3.1415926

This is ok, but
Remark: instead of this you could also write

from math import pi

(just in case you cannot remember the desired
number of decimals of pi)
>
>
> def areacircle(x)
> return pi * square(x)
>

Again:
1. add ":" in the  def-line
2. indent second line

def areacircle(x):
   return pi * square(x)


> then, after you type those in, try this:
>
> R = input("Please input the radius of the circle please?")
> # That input will BOMB if you input anything but a number!
> print areacircle(R)
>
> Try it. Are we having fun yet?
>
>
>
> Iain Long wrote:
> >
> > I was reading about instant hacking so i clicked the windows icon and
run
> > and typed in notepad... and did an example that was shown...
> >    radius = 30
> >
> >    print radius*radius*3.14 .... i don't know what to do next
> >


I suppose, Iain, your problem is another one:
You want to know how to execute those two statements above.
It does not suffice to type it into an editor.
You may use either of two ways:

In any case you have to have installed you Python-interpreter. (You can
get it from http://www.python.org)


1. way:
-------
If you start it, you will see a prompt:

>>>

There you can input Python statements

>>> radius = 30
>>>

(If you doubt, that this changes something in your computer,
you may type:

>>> radius
30
>>>

So this value 30 is stored in a variable called radius)

Then continue:

>>> print radius*radius*4.14
2826.0

... prints the interpreter


2. way:
-------

Youo save, what you typed into notepad as a Python-script,
for instance as circle.py

Then you ask your interpreter to execute it:

open the MSDOS-prompt (or a terminal, a shell or whatever if you
doesn't use Windows) and type

c:\Python21>python circle.py

This will result in displaying

2826.0


Hope that helps
Gregor

_________________________________________________________________
> > Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp.
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> --
> Respectfully,
>              -Kirk D Bailey (C)2001
>               Addme! icq #27840081
> end
>
>
> Within the sweep of his sword, Each man is an Ubar.
>
> http://www.howlermonkey.net/
> http://www.sacredelectron.org/
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>