# Calculate volume and surface area of a sphere given its radius as inpu

Page 1 of 1

## 2 Replies - 15542 Views - Last Post: 31 August 2009 - 07:52 PMRate 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=123135&amp;s=75f2adc41285283818c6351fa21fd419&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 joliejoe13

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 28-August 09

# Calculate volume and surface area of a sphere given its radius as inpu

Posted 31 August 2009 - 10:10 AM

import math
def main():
v=math.pi*(4/3)*(r**3)
a=math.pi*4*(r**2)
return
print "Solution of volume:",volume(radius),"and solution of area",area(radius)

[b]The second part is the error that is generated and i am not able to understand it and how to solve it...

IDLE 1.2 ==== No Subprocess ====
>>>
Traceback (most recent call last):
File "C:\Documents and Settings\user\My Documents\Lecture Notes\Programming Methodology\Labsheet Programming Methodology\Areasphere&volumeW2Q2.py", line 10, in <module>
ValueError: invalid literal for float(): "7"
>>>

Is This A Good Question/Topic? 0

## Replies To: Calculate volume and surface area of a sphere given its radius as inpu

### #2 code_m

Reputation: 24
• Posts: 202
• Joined: 21-April 09

## Re: Calculate volume and surface area of a sphere given its radius as inpu

Posted 31 August 2009 - 10:15 AM

Where did you define the variable "r" ???

### #3 Nallo

• D.I.C Regular

Reputation: 163
• Posts: 256
• Joined: 19-July 09

## Re: Calculate volume and surface area of a sphere given its radius as inpu

Posted 31 August 2009 - 07:52 PM

There are several problems here:
1. Please, when you post code use the code /code tags. Otherwise the identitation is omitted.
2. Your Error Message: When the program prompted you to input a radius you typed in "7" or '7' instead of just 7. The string "7" contains characters, that are not numbers or a decimal point ( the qoutation marks). So python cannot convert that to a float.
3. It seams you haven't understood how functions work. A function looks like the following. Am argument is passed to the function, some computation is done with it and a result is returned. Your code doesn not look like that!
```def double_up(value):
result = value * 2
return result

val = 4

#this will print 8
print double_up(val)

```