def run(self): # Run the main program
print("Welcome to {}!\nLogin at: {}\nType 'help' for manual, 'exit' to terminate the program.".format(self.bank_name, datetime.datetime.now())) # Print welcome message
user_input = ""
while user_input != "exit": # Start main loop
# Wait until user input is 'quit', which terminates the program.
print('==========================================')
user_input = input()
# Do actions for input
try:
if user_input == CommandLineProgram.ACTION.HELP:
# If user command is 'help'
print("'help': This command.\n'exit': Close all session and terminate.\n'add user': Add a new user to the session.\n'list users': List all users.\n'add transaction': Add transaction to an existing user.'generate report': Print report for an existing user.")
elif user_input == CommandLineProgram.ACTION.ADD_USER:
# If user command is 'add user'
users.append(user.User(input("Please input username!")))
elif user_input == CommandLineProgram.ACTION.LIST_USERS:
# If user command is 'list users'
i = 0
for item in users:
print("{}. {}".format(i, item.name))
i = i + 1
elif user_input == CommandLineProgram.ACTION.ADD_TRANSACTION:
# If user command is 'add transaction'
self.prompt_user_selection().add_transaction(Transaction(input("Amount of transaction:")))
elif user_input == CommandLineProgram.ACTION.GENERATE_REPORT:
# If user command is 'print report'
self.print_all_transaction(self.prompt_user_selection())
except Exception:
print("Try again")
评论列表
文章目录