문제

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).

도움이 되었습니까?

해결책

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)

다른 팁

You are not calling your function properly, do this:

ring_size = areaOfRing(r_out, r_in)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top