你会怎么做到这样一个选项可以回到另一个菜单?

时间:2017-01-28 08:15:53

标签: python python-3.x

它不完美我知道但是对于选择收件箱,发送和垃圾邮件我想做到这样它返回到菜单而不是主菜单。

请帮助并谢谢

def menu():

    print("""

    <<<<<<<<<<<<<<<<<<<<>>>>>>>>
    1.Sign In||2.Create Account|
    3.Exit   ||                |
    <<<<<<<<<<<<<<<<<<<<>>>>>>>>
      """)


    ans=input("What would you like to do? ")
    if ans=="1":
        email()
    elif ans=="2":
        sign()
    elif ans=="3": 
        print("\n Goodbye") 
        ans = None
    else:
        print("\n Not Valid Choice Try again")

import re
def email():
    email = input("Enter Your email: ")
    match = re.search(r'[\w.-]+@[\w.-]+.\w+', email)

    if match:
        print ("Valid email, Your are now logged in :D "), match.group()
        print("""

    <<<<<<<<<<<<<<<<<<<<>>>>>>>>
    1.Inbox||2.Spam             |
    3.Sent ||                   |
    <<<<<<<<<<<<<<<<<<<<>>>>>>>>
      """)
    else:
        print ("Not valid,Try Again! ")

    choice=input("Pick Your Choice:")
    if choice=="1":
        inbox()
    elif choice=="2":
        spam()
    elif choice=="3":
        sent()
        choice = None
    else:
        print("Not valid,Try Again! ")

def sign():
    user = input('Create Email: ')
    password = input('Create Password: ')
    print("You have now created your account, go back to the menu to sign in!")
    anykey=input("Enter anything to return to the menu")
    menu()
    store_user = [brandonbiba@gmail.com]
    store_pass = [brandon]

def inbox():
    print("You have no mail, come back later.")
    anykey=input("Enter anything to return to the menu")
    menu()
def sent():
    print(" You have sent 1 piece of mail to m.mazi@gmail.com ")
    anykey=input("Enter anything to return to the menu")
    menu()
import random
def spam():
 random.randrange(1,1000)
print("This is how much spam you have!")

menu()

它不完美我知道但是对于选择收件箱,发送和垃圾邮件我想做到这样它返回到菜单而不是主菜单。

1 个答案:

答案 0 :(得分:0)

您可以将控制权交还给任何调用inbox()sent()的函数。使用return语句而不是在上述2个函数中调用menu()。像这样:

def inbox():
    print("You have no mail, come back later.")
    anykey=input("Enter anything to return to the menu")
    return

def sent():
    print(" You have sent 1 piece of mail to m.mazi@gmail.com ")
    anykey=input("Enter anything to return to the menu")
    return