3 Replies - 886 Views - Last Post: 13 April 2013 - 11:04 AM Rate Topic: -----

#1 javathehut.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 11-April 13

python. compute volume given radius

Posted 11 April 2013 - 06:14 PM

I am very very new to Python, and am attempting to write a program that, when the user types in a random radius of a sphere, the program prints something like: the surface area is______ the volume is_________. However, I am having much trouble in how to approach this. Are defining these functions even necessary? And I am unsure of how to relate the input value ® to my functions of Volume and Surface Area :(




Python 3.3.1 (v3.3.1:d9893d13c628, Apr  6 2013, 20:30:21) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import math
>>> input ('enter a number')
enter a number
''
>>> r = ('enter a number')
>>> input ('enter a number')
enter a number 5
' 5'
>>> def SurfaceArea():
	4*math.pi*r**2
	print('the volume is %d)
	      
SyntaxError: EOL while scanning string literal
>>> def Volume():
	4/3*math.pi*r**2
	print ('the volume is %d)
	       
SyntaxError: EOL while scanning string literal
>>> 


Is This A Good Question/Topic? 0
  • +

Replies To: python. compute volume given radius

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,672
  • Joined: 13-March 10

Re: python. compute volume given radius

Posted 11 April 2013 - 06:22 PM

You need to store somewhere the input - variables are for it.

def area(number):
     return calulcation involving number


number = int(input("Enter a number:  "))
value = area(number)

Was This Post Helpful? 0
  • +
  • -

#3 woooee  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 68
  • Joined: 21-November 12

Re: python. compute volume given radius

Posted 13 April 2013 - 10:52 AM

It appears you are using the command line; use Idle at the very least as you can go back and edit code an run it again as well as save it to a file if you want.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,576
  • Joined: 12-December 12

Re: python. compute volume given radius

Posted 13 April 2013 - 11:04 AM

To explain the original error messages, you haven't closed your string with an apostrophe:

    print('the volume is %d', parameter)

But you haven't defined parameters for your functions:

    def Volume(parameter):

You can still call your functions from the command-line:

Volume(4)    # calls the Volume() function defined earlier. Or,
Volume(r)

This post has been edited by andrewsw: 13 April 2013 - 11:06 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1