Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please help me solve this.I want to make the mainmenu appear only after succesful sign up and if the username and password is wrong back to main page

What I have tried:

<pre>print("\n Welcome to Covid 19 Vaccination App ")
def SignUp_login(welcome):
    if welcome == "1":
        name=input('\nEnter Your Name: ')
        username  = input("\nEnter a username:")
        phone=input('\nEnter Your Phone number: ')
        password  = input("\nEnter a password:")
        password1 = input("\nEnter a Confirm password:")
        if password == password1:
            try:
                file = open(username+".txt", "r")
                data   = file.readline().split(':')
                if username in data[1] and password in data[-1]:
                    print("\nUser already found")
                    mainmenu
                
            except:
                file = open(username+".txt", "w")
                file.write(name+':'+username+':'+phone+":"+password)
                file.close()
                print('\nYou Successfully SignUp !')
                mainmenu
        else: print("\nPasswords do NOT match !")
        SignUp_login
    elif welcome == "2":
        login1 = input("\nUserName : ")
        login2 = input("\nPassWord : ")
        try:
            file = open(login1+".txt", "r")
            data   = file.readline().split(':')
            if login1 in data[1] and login2 in data[-1]:
                print("\nWelcome")       
        except:
            print('\nUser not found please Sign Up!')
            SignUp_login if FileNotFoundError else SignUp_login
welcome = input("\n1. SignUp \n2. Login \n\n")
SignUp_login(welcome)

def mainmenu():
   print("What would you like to do?")
print("1. View Medical History and Status")
print("2. Update Medical History")
print("3. Check Vaccination Appoinment(Date,Time,Location)")
print("4. Quit")
selection=int(input("PLease Enter a choice: "))
def Status():
    print('Your Status is currently')
def Fill():
    print('l')
def Check():
    print('Your Appoiment Is Currently at')
if selection==1:
    Status()
elif selection==2:
    Fill()
elif selection==3:
    Check()
elif selection==4:
    exit()  
else: print("Invalid choice.Please Enter A Valid Choice from 1 - 4")
Posted
Updated 4-Nov-21 22:20pm

Don't try to call the function you are in: SignUp_login - that's called recursion and it's a bad idea unless the algorithm specifically needs it - it can cause your app to freeze or crash.
Instead, use a loop: Loops - Learn Python - Free Interactive Python Tutorial[^] and only exit teh loop when you have a valid login.
 
Share this answer
 
You should reorganise your code thus:
Python
def SignUp_login(welcome):
#
# the signup code
#
# return True or False to indicate successful login
#


def mainmenu():
#
# the menu code
#


# the main loop starts here

status = False
for i in range(3): // only try this a fixed number of times
    welcome = input("\n1. SignUp \n2. Login \n\n")
    status = SignUp_login(welcome)
    if status == True:
        break

# if login was successful then show the main menu
while status == True:
    mainmenu()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900