Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果函数返回用户输入的值,我如何在另一个函数中使用该值而不要求用户输入另一个值_Python - Fatal编程技术网

Python 如果函数返回用户输入的值,我如何在另一个函数中使用该值而不要求用户输入另一个值

Python 如果函数返回用户输入的值,我如何在另一个函数中使用该值而不要求用户输入另一个值,python,Python,“”“我发现第二个函数再次请求用户输入,而我不希望这样,相反,我只需要用户在第一个函数”“中已经给定的值。”您需要获取userChoice()的结果,并将其作为参数传递给useValue()。试试这个: def userChoice(): print("Press 1 to send text message\n Press 2 to share file") action = int(input("Please what do you want t

“”“我发现第二个函数再次请求用户输入,而我不希望这样,相反,我只需要用户在第一个函数”“中已经给定的值。”

您需要获取
userChoice()
的结果,并将其作为参数传递给
useValue()
。试试这个:

def userChoice():
    print("Press 1 to send text message\n Press 2 to share file")
    action = int(input("Please what do you want to do ? "))
    return action


def useValue():
    value=userChoice() + 1
    print(value)

userChoice()
useValue()

按照您的方式,对
userChoice
的第一次调用从用户那里获得一个输入,并且从不使用它做任何事情。然后,当调用
useValue
时,它会获取另一个用户输入,并将其用于打印输出。

def userChoice():print(“按1发送文本消息\n按2共享文件”)action=int(输入(“请做什么?”))返回action def useValue(选择):value=choice+1打印(值)user\u input=userChoice()useValue(user\u input)我不确定我是否理解你的要求。如果需要在原始问题中添加澄清信息,可以通过编辑问题而不是在注释中进行编辑(注释中的代码格式不太好)。如果你有一个不同的问题,你可能想打开一个新的问题。记住接受一个能解决你的问题的答案,并对那些你觉得有用的进行投票。听起来你从一个指南或教程中得到的好处比一个简单的问题要多。
def userChoice():
    print("Press 1 to send text message\n Press 2 to share file")
    action = int(input("Please what do you want to do ? "))
    return action


def useValue(choice):
    value=choice + 1
    print(value)

user_input = userChoice()
useValue(user_input)