、括弧内の部分は、あります。引数は入力と考えることができます。入力を伴う関数を定義した後、その関数に入力を与えないと、pythonはエラーを返します。このコードを修正する方法は2つあります。
方法1(ここではあなたの関数は、任意の入力/引数を必要としない):それは関数の内部で冗長になるので
import math
def sphereArea(): #Just get rid of the argument in your function definition
radius= int(input("The number you want as radius:"))
surface_area= 4*math.pi*radius**2
print("The surface area of the sphere is = ", surface_area)
sphereArea()
方法2(我々は、入力行を移動するアイデアは、あなたのパスが値です。関数への入力として):
import math
def sphereArea(radius):
radius= int(input("The number you want as radius:"))
surface_area= 4*math.pi*radius**2
print("The surface area of the sphere is = ", surface_area)
required_radius= int(input("The number you want as radius:"))
sphereArea(required_radius) #You have now passed your value into the function to be used.
出典
2017-11-07 00:26:25
Tim
あなたのコードを使用して最後にsphereArea()を入力した後、残念ながら私は同じエラーを返します。私は使用しないと思いますそれとも? – Allucard12
繰り返してください:関数sphereAreaの定義には、パラメータ 'radius'が含まれています。これは、関数が呼び出されると、radiusの代わりに引数が渡される必要があることを意味します。したがって、sphereAreaを呼び出すときには、小文字の間に数字を渡す必要があります。すなわちsphereArea(10)、またはsphereArea(some_variable)。他の関数には、add(6,10)やadd(10、some_number)などの複数のパラメータがあります。とにかく、私が書いたコードでは、あなたの関数はすでに呼び出され、あなたが引き出したようにユーザーの入力である変数を渡しています。 – Radish