Abyss_QQ 2021-06-04 13:53 采纳率: 100%
浏览 51
已采纳

python,请问如何将函数内的返回值,调入进下一函数中

如何将start函数中的返回值origina_code,调入进sys函数中呢?

最后这样调用会将start函数执行两次,有时还会执行错误。

 

def start_system():
    print("Please input your student number: \n")
    input("Your student number:\n")
    print("Please input your code:\n")
    original_code = int(input("Your code:"))

    print("Welcome come to student system")
    print("---------------Student System---------------")
    print("     1.更改信息                 2.更改账号" + "\n"
          "     3.更改密码                 4.删除账号" + "\n"
          "     5.添加选课                 6.退出系统" + "\n"
          )
    print(original_code)
    return original_code


def sys_choice(operation_a, original_code):
    if operation_a == 1:
        input("Please input your old information:")
        input("Input your new information:")
        print("Mission success!")

    elif operation_a == 2:
        print("You have not access to achieve this operation!")

    elif operation_a == 3:
        original_code1 = int(input("Please input your original code:"))
        if original_code1 == original_code:
            new_code1 = int(input("Input your new code:"))
            new_code2 = int(input("Make sure your new code:"))
            if new_code2 == new_code1:
                print("Operation is successful !")
            else:
                print("Error !, your input is different !")
        else:
            print("input is error !")

    elif operation_a == 4:
        print("Do you delete your number?")
        choice4 = input("Please input your choice:")
        if choice4 == 'y':
            print("OK")
        else:
            print("Error !")

    elif operation_a == 5:
        print("choose your course:")

    elif operation_a == 6:
        choice6 = input("Are you sure log out the student system ?")
        if choice6 == 'y' or 'yes':
            print("Exit the success !")
        elif choice6 == 'n' or 'no':
            print("Cancel out !")

    else:
        print("Your input is error. Please input your choice again.")



'''如何让start返回code进入到sys中'''

start_system()
print("----------------\n")
operation_a = int(input("Make your choice:"))
sys_choice(operation_a, original_code=start_system())
  • 写回答

3条回答 默认 最新

  • PythonJavaC++go 2021-06-04 14:33
    关注
    start_system()
    print("----------------\n")
    operation_a = int(input("Make your choice:"))
    sys_choice(operation_a, original_code=start_system())
    
    
    # 最后这4行更改如下
    
    original_code = start_system()
    print("----------------\n")
    operation_a = int(input("Make your choice:"))
    sys_choice(operation_a, original_code)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试