Python Forum
radius of circle question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
radius of circle question
#1
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))
Reply
#2
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: '
Reply
#3
(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
Reply
#4
Well spotted @Sagar, I missed that. I only noticed 2 mistakes that make code unable to run (in first and last line).
Reply
#5
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))
Reply
#6
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How Can I Draw Circle With Turtle İn Python ? mdm 2 2,737 Jun-03-2021, 02:07 PM
Last Post: DPaul
Photo I need help with a circle random color code and error Vxploit 4 3,001 Mar-21-2021, 07:23 PM
Last Post: jefsummers
  Turtle circle Fabio87 3 2,467 Dec-17-2020, 10:52 PM
Last Post: Fabio87
  Calculate area of a circle pythonuser1 20 6,949 Apr-15-2020, 03:18 AM
Last Post: Skaperen
  Intersection of a triangle and a circle Gira 3 3,592 May-19-2019, 06:04 PM
Last Post: heiner55
  function with radius as a parameter that returns area of a circle taydeal20 4 7,164 Feb-07-2018, 03:33 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020