Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db = dict()
- #Empty list that acts as a database
- state = False
- #State defined to start and stop while loop which acts as our on off switch for the database
- def get_user():
- user1 = input("What is your username?\n")
- user = user1
- return user
- def get_pass():
- password = input("What is your password?\n")
- return password
- def login():
- #This is going to be called when user says he is logging in.
- #user and pass variables used to check in db for existing usernames
- user = get_user()
- password = get_pass()
- #if checks through every object in database to see if user and pass are in db
- if user in db and password == db[user][0]:
- print("Hello ", user,"\n")
- loginchoice(user)
- return user
- #Else catches if username and pass fail and call back decision function
- else:
- print("Error: Username or Password incorrect.\n")
- userinput()
- def signup():
- #This is called when user chooses signing up
- #user and pass variables used to check in db for existing usernames
- user = input("What is your username?\n")
- password = input("What is your password?\n")
- #Boolean tree used if signup username is original and adds the input into database
- if user not in db:
- db[user] = [password, 0]
- print("Sign up complete. Please attempt to login. \n")
- userinput()
- #If boolean check fails it means there is identical username in database and it cannot add it
- else:
- print("This username already exists, please try again.\n")
- userinput()
- def test():
- #This function prints out the db to make sure we are adding users and passwords to database
- print(db)
- userinput()
- def userinput():
- #State activates while loop and "turns on" our database
- state = True
- #This function asks the user on whether they want to login or signup
- #Because it is setup this way it gives the user the ability to choose from several options.
- question = input("Press G to login, Press S to signup, Press T for test, or press Q to quit.\n")
- if question.lower() == 'g':
- login()
- elif question.lower() == 's':
- signup()
- elif question.lower() == 't':
- test()
- elif question.lower() == 'q':
- state = False
- print("Thanks for your time! Login soon.\n")
- else:
- print("ERROR: Invalid input\n")
- userinput()
- def check_balance(user):
- print("Your balance is:", db[user][1])
- loginchoice(user)
- def deposit(user):
- print(user)
- deposit = input("How much would you like to deposit?\n")
- db[user][1] += int(deposit)
- print("Your new balance is now:", db[user][1])
- loginchoice(user)
- def withdraw(user):
- withdraw = input("How much would you like to withdraw?\n")
- db[user][1] -= int(withdraw)
- print("Your new balance is now:", db[user][1])
- loginchoice(user)
- def loginchoice(user):
- #This function is called when login is successful.
- #It gives a further decision tree for logged in users.
- choice = input("What would you like to do?\n1.) Check balance. \n2.) Deposit money \n3.) Withdraw money \n4.) Back to menu. \n")
- if int(choice) == 1:
- check_balance(user)
- elif int(choice) == 2:
- deposit(user)
- elif int(choice) == 3:
- withdraw(user)
- elif int(choice) == 4:
- userinput()
- else:
- print("ERROR: Invalid input\n")
- loginchoice(user)
- def game_start():
- userinput()
- while state == True:
- #While loop initiates database start and calls functions when needed.
- user = get_user()
- game_start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement