Newbie questions
Jim Mace
jmace at ior.com
Fri Jun 16 13:55:52 EDT 2000
#circumference calculator
print "This calculates the circumference of a circle"
PI = 3.141592645
R = input ("Enter the radius of your circle here: ")
C = 2*PI*R
print
print "The circumference of your circle is: %0.11f" % (C)
print
print """You can use any number you need to for how ever any decimal places
you want to go out to. For example, I used %0.11f to do out four
decimal places, but if you want to go out more just change the value
of n in %0.(n)f. This is a little more simple for a newer programmer
that may not have any programming experience with built in functions
and definitions."""
Jim Richardson <warlock at eskimo.com> wrote in message
news:slrn8kdfhg.10b.warlock at troll.myth...
> On Mon, 12 Jun 2000 21:10:35 -0700,
> jim roush, in the persona of <jar at mminternet.com>,
> brought forth the following words...:
>
> >I'm just learning Python. The following code does not work. It's
> >supposed to calculate the circumference after the user enters the
> >radius. The program displays the prompt, but when I enter the radius
> >and the press enter, nothing happens.
> >
> >FYI, I'm using Python 1.5.2 on WinNT.
> >
> >pi = 3.141592654
> >radius = input("Enter is the radius: ")
> >circ = 2 * pi * radius
> >print circ
> >
> >
> I am just a newbie but the following code works for me (on linux, hence
> the #! first line)
>
> #!/usr/bin/env python
> import string,math
> #Import string for the atoi function, since raw_input returns a string
> #Import math so pi has many digits :)
>
> radius=string.atoi(raw_input('Radius? '))
> circ = 2*math.pi*radius
>
> print circ
>
> #Or to print circ to only 2 places
>
> print 'Circumference is %.2f'%circ
> --
> Jim Richardson
> Anarchist, pagan and proud of it
> WWW.eskimo.com/~warlock
> Linux, because life's too short for a buggy OS.
>
More information about the Python-list
mailing list