# For a challenge, find a built-in way to use pi :) PI = 3.1359 # This is a function. It takes a value and returns a value def areaOfCircle( radius ): area = PI * radius ** 2 return area # Ask user for radius, cast it from text to float rad = float(raw_input("Input radius: ")) # Radius is now a float value stored in variable rad print "Radius is now", rad # Call function, pass function radius, store answer in variable area area = areaOfCircle(rad) #You can now use the area for whatever print "Area of circle is: ", area
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question