Python Forum
radius of circle question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: radius of circle question (/thread-4823.html)



radius of circle question - charlottecrosland - Sep-11-2017

I'm trying to run this, and it doesn't work. I accept it's a ridiculously easy program. And I'm obviously missing something terribly obvious and easy. But it's still frustrating. Any pointers gratefully received.

radius=input( float( 'Radius of circle: ' ))
print( 'Radius of circle:' , radius , 'cm')
circArea=((3.1429*radius)**2)
print( 'Area of Circle:' , round(ciracArea,2))


RE: radius of circle question - j.crater - Sep-11-2017

Hello, when posting on this forum, please put the code in Python tags next time (see this for help). Also, it is desired for posts to be more specific about what is not working / what happens when you run it.

That said, you are not far from correct code. See if you can figure why the line below breaks.
radius=input( float( 'Radius of circle: ' )) 
Hint - order of operations. Error message says: ValueError: could not convert string to float: 'Radius of circle: '


RE: radius of circle question - Sagar - Sep-11-2017

(Sep-11-2017, 05:28 AM)charlottecrosland Wrote: I'm trying to run this, and it doesn't work. I accept it's a ridiculously easy program. And I'm obviously missing something terribly obvious and easy. But it's still frustrating. Any pointers gratefully received.

radius=input( float( 'Radius of circle: ' ))
print( 'Radius of circle:' , radius , 'cm')
circArea=((3.1429*radius)**2)
print( 'Area of Circle:' , round(ciracArea,2))

Area of circle is 3.1429 * (radius ** 2).
Here you have written:
(3.1429*radius)**2


RE: radius of circle question - j.crater - Sep-11-2017

Well spotted @Sagar, I missed that. I only noticed 2 mistakes that make code unable to run (in first and last line).


RE: radius of circle question - Sagar - Sep-11-2017

The correct code probably should look like this:
    radius=float( input('Radius of circle: ' ))
	print( 'Radius of circle:' , radius , 'cm')
	circArea=3.1429*(radius**2)
	print( 'Area of Circle:' , round(circArea,2))



RE: radius of circle question - charlottecrosland - Sep-11-2017

j.crater and Sagar thank you both very much for your replies. I'm (obviously) new to this and I'm making silly mistakes. Thank you for taking the time to point out my errors.

And point taken about being more explicit with what the error is. And I'll use the Python code tags in future. I appreciate this makes it easier for people to answer questions.