I am very new to Python, and I am trying to write a program that returns the Area and Volume of a sphere when the user inputs the radius. I thought I had a solid program while typing it up:
Expand|Select|Wrap|Line Numbers
- import math
- def sphere():
- Radius = input("Please enter the radius of the sphere and press Enter: ")
- Volume = (4/3*math.pi*Radius**3)
- Area = (4*math.pi*Radius**2)
- Print Volume
- Print Area
- sphere()
Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
sphere()
NameError: name 'sphere' is not defined
Upon further instpection, when I try to run the chaos.py program (taken directly from Zelle's "Python Programming: An Introduction to Computer Science"):
Expand|Select|Wrap|Line Numbers
- def main():
- print "This Program illustrates a chaotic function."
- x = input("Enter a number between 0 and 1: ")
- for i in range (10):
- x = 3.9 * x * (1-x)
- print x
- main()
Traceback (most recent call last):
File "<pyshell#0>", line 1, in ?
main()
NameError: name 'main' is not defined
Any suggestions would be much appreciated.
I'm using 2.4.4 on Windows Vista.
Thanks!