Вопрос

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