如何将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())
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)
同一个程序内的两个函数直接用返回值名称调用就可以,两个程序的话import一下,如果import没有找到那就添加一下PYTHONPATH
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632