Question

import math 
r_out = int(input("Insert rings outside raadius: ")) 
r_in = int(input("Insert rings inner raadius: "))

# ring size calculating function
def areaOfRing(r_out, r_in):
    r_outs = (r_out**2)*math.pi
    r_ins = (r_in**2)*math.pi
    ring_size  = r_outs - r_ins
    return ring_size

ring_size = areaOfRing 
print('Ring size is = ',ring_size)

I tried to print out the answer as it should do when you put the 2 numbers inside. After I made it run I got a NameError. Yes. I did tried ring_size = areaOfRing(), and ring_size = areaOfRing(r_out, r_in) gave me both errors.

(Note, After I restarted the program, it started to work with @ Martijn's help).

Was it helpful?

Solution

You need to supply arguments while calling function.

import math


# ring size calculating function
def areaOfRing(r_out, r_in):
    r_outs = (r_out**2)*math.pi
    r_ins = (r_in**2)*math.pi
    ring_size  = r_outs - r_ins
    return ring_size

r_out = int(input("Insert rings outside raadius: ")) 
r_in = int(input("Insert rings inner raadius: "))

ring_size = areaOfRing(r_out, r_in) 
print('Ring size is = ',ring_size)

OTHER TIPS

You are not calling your function properly, do this:

ring_size = areaOfRing(r_out, r_in)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top