Skip to content
← Back to Community
User Defined Functions
Profile icon
Kritini2030

Can you call a variable from one user-defined function into another user defined function?

How?

Answered by themining72 [earned 5 cycles]
View Answer
Comments
hotnewtop
Profile icon
themining72
# User Radius def radius(): radius = input("Enter Radius: ") r = float(radius) print("Radius =", r) return r # Calculations def calculate(r): area = 3.14 * r * r print ("Area =" , area) # Magic n = input("If you would like to continue, type yes with a SMALL/LOWERCASE Y.") while n == "yes": calculate(radius())

The above should work, changes:

  • Line 10 removed.
  • Line 9 now accepts a variable.
  • Line 16 removed.
  • Line 17 calls Calculate(r) and gives r as radius()
Profile icon
VulcanWM

instead of printing the answer try returning it
and the variable will be
var_name = function()