# python. compute volume given radius

Page 1 of 1

## 3 Replies - 4678 Views - Last Post: 13 April 2013 - 11:04 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=318282&amp;s=8894b48890eec64c2544151779748e9b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 javathehut.

Reputation: 0
• Posts: 6
• 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
>>> 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

• D.I.C Lover

Reputation: 203
• Posts: 1,717
• 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)
```

### #3 woooee

Reputation: 27
• Posts: 109
• 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.

### #4 andrewsw

• But the opposite, you said.

Reputation: 5534
• Posts: 21,841
• 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

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}