我如何在另一种方法中使用输入值?

问题描述 投票:0回答:1

我将输入放入下面的

read():
函数中,但其他函数如
calculate():
write():
无法定义输入。 有人可以帮助我吗?

def read (): 
    foot = int(input("Foot?")) 
    inch = int(input("Inch?")) 
def calculate (): 
    foot_to_meter = 0.3048 * foot 
    foot_to_centimeter = 155 * foot_to_meter 
    inch_to_meter = (1.5 / 12)*5.4530* inch 
    inch_to_centimeter = 155 * inch_to_meter 
def write(): 
    print ("The ", foot, " foot is ", foot_to_meter, " meter" ) 
    print("The ", foot, " foot is ", foot_to_centimeter, " centiMeter") 
    print("The ", inch, " inch is ", inch_to_meter ," meter") 
    print ("The ", inch, " inch is ",inch_to_centimeter, " centiMeter") 
def main(): 
    read () 
    calculate () 
    write()
main()

我的输入参数无法在 calculate():write(): 函数中定义。

python function input methods syntax-error
1个回答
0
投票

您正在寻找关键字

return
以及为函数提供参数的一般功能,这将允许使用该命名参数“调用”它们,然后在其中按该名称使用它!

例如

>>> def test1(arg):     # function accepts one argument named arg
...     return arg + 3  # named here, the result of which is returned
... 
>>> test1(2)            # call the function and pass an argument to it
5
© www.soinside.com 2019 - 2024. All rights reserved.