函数不返回字符串值

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

我想从我的消息函数返回m&t的字符串值,以在密码函数中使用以执行while循环,并且一旦错误打印消息反向。我收到的错误消息是“NameError:name'm'未定义”,但是在消息中定义了'm',我试图返回以便在密码中使用't'。

def main():
    message()
    cipher(m, t)


def message():
    m = input("Enter your message: ")
    t = ''
    return m, t


def cipher(m, t):
    i = len(m) - 1
    while i >= 0:
        t = t + m[i]
        i -= 1
    print(t)


if __name__ == '__main__': main()
python function return-value
1个回答
5
投票

当您调用message()函数时,需要存储返回值。

def main():
    m, t = message()
    cipher(m, t)
© www.soinside.com 2019 - 2024. All rights reserved.