Skip to content

Commit

Permalink
Function provided with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ljonkergouw committed Nov 25, 2022
1 parent a29be49 commit 0f799dc
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions PythonTrainingGroupB/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,37 @@
from Portfolio import *

def load_accounts(path):
""""
:param path: The name of the json file that serves as input.
:return: This function returns the json file such that it can be used for data analysis.
"""

f = open(path)
return json.load(f)

def add_new_account(path, accounts, new_username, new_password):
""""
add_new_account creates a new entry in the json database for new users with their username and the password.
:param path: the path where we want to write the output to.
:accounts: the json file of existing accounts that serves as input.
:new_username: The username specified by the user.
:new_password: The password specified by the user.
:return: This function updates the json file with account information of the new user.
"""

accounts[new_username] = new_password
with open(path, 'w') as fp:
json.dump(accounts, fp)

def login(accounts):
"""
login asks the user whether they want to sign up, or want to log in to their existing account.
:param accounts: the json file of existing accounts.
:return: This returns the username of the new or existing user.
"""

print("Welcome to our Investment Game! If you want to sign up, press '0'. If you already have an account, press '1' to log in.")

choice = int(input("Please make your choice: "))
Expand All @@ -24,6 +46,13 @@ def login(accounts):
return login

def new_login(accounts):
""""
new_login asks the user for a username and password, which will be documented in the system.
:param accounts: the json file of existing accounts.
:return: This returns the new username.
"""

new_username = input("Please enter a username: ")
while new_username in accounts:
print("User name already exists, please enter another username: ")
Expand All @@ -38,6 +67,13 @@ def new_login(accounts):


def existing_login(accounts):
""""
exisiting_login asks the user for its username and password, in order to log in.
:param accounts: the json file of existing accounts.
:return: This returns the existing username.
"""

print("Please enter you username.")

while True:
Expand Down

0 comments on commit 0f799dc

Please sign in to comment.