def mainmenu(clientname, accountcheck): while True: view.show_mainmenu(clientname, accountcheck) selection = view.get_input() print(selection) if selection == '1': view.show_balance(model.get_balance(clientname)) elif selection == '3': model.add_fund(clientname, view.get_deposit()) elif selection == '2': model.withdraw(clientname, view.get_withdraw()) pass elif selection == '4': view.goodby() initialmenu() else: view.bad_input()
def start(): while True: selection = v.get_initial_menu_choice() print(f'this was the selection: {selection}') #is it better to test for quit first or go in same order as menu? if int(selection) == 1: #create account first_name, last_name, pin = v.create_account_prompt() account = Account() account_num = account.create_account(first_name, last_name, pin) account.save_account() account.save_file() v.confirm_account_creation(account.account_num) elif int(selection) == 2: #login account = Account() account_num, pin = v.login_prompt() authenticated_user = account.login(account_num, pin) #if the login is successful -- validated by model show next menu while authenticated_user: selection = v.get_main_menu_choice( authenticated_user.first_name, authenticated_user.last_name, authenticated_user.account_num) if int(selection) == 1: #check balance v.show_balance(authenticated_user.get_balance()) elif int(selection) == 2: #withdraw amount = v.withdrawal_prompt() authenticated_user.withdraw(amount) authenticated_user.save_account() authenticated_user.save_file() elif int(selection) == 3: #deposit amount = v.deposit_prompt() authenticated_user.deposit(amount) authenticated_user.save_account() authenticated_user.save_file() elif int(selection) == 4: #quit v.confirm_quit() break elif int(selection) == 3: v.confirm_quit() break
def mainmenu(account): while True: view.show_menu(account) selection = view.get_input() if selection == '4': answer = view.quit_input() if answer == "y": model.save() break if answer == "n": view.show_menu(account) elif selection == '1': balance = model.check_balance(account) view.show_balance(balance) elif selection == '2': depbalance = float(view.get_amount_input()) model.deposit(account, depbalance) balance = model.check_balance(account) view.show_balance(balance) elif selection == '3': wdbalance = float(view.get_amount_input()) model.withdraw(account, wdbalance) balance = model.check_balance(account) view.show_balance(balance) else: view.bad_input()
def user_menu(user_account): while True: view.show_user_menu() selection = view.get_input() if selection == "4": return elif selection == "1": view.show_balance(model.get_balance(user_account)) elif selection == "2": print("wit") withdraw_amount = int(view.subtract_funds()) current_balance = int(model.get_balance(user_account)) if withdraw_amount > current_balance: print("insufficient funds") else: model.withdraw_funds(user_account, withdraw_amount) elif selection == "3": add_amount = view.add_funds() model.add_funds(user_account, add_amount) else: view.bad_input()
def start(): selection = 0 while selection != 3: selection = v.mainmenu() if selection == 1: # Create account pin, first, last = v.create_account() newaccount = m.Account() newaccount.create_account(pin, first, last) v.create_acc_success(newaccount.account_num) start() if selection == 2: #Log in account_num, pin = v.login() account_num = str(account_num) account = m.Account(account_num) account_details = account.login(account_num, pin) if account != None: option = 0 while option != 4: option = v.account_options(account_details) if option == 1: # Show Balance v.show_balance(account.balance) elif option == 2:# Withdraw Funds amount = v.withdraw_funds() if account.withdraw(amount) == False: v.insufficient_funds else: v.withdraw_message(amount) v.show_balance(account.balance) elif option == 3:# Deposit Funds amount = v.deposit_funds() account.deposit(amount) v.show_balance(account.balance) start() # Back to create/login menu
def game_loop(): start = view.start_up_menu() if start == "s": (user_name, password) = view.sign_up_menu() model.sign_up(user_name, password) else: (user_name, password) = view.logg_in_menu() _id = model.user_check(password) print(_id) while 1: buy_inputs = ['b', 'buy'] sell_inputs = ['s', 'sell'] lookup_inputs = ['l', 'lookup', 'look up', 'look-up'] quote_inputs = ['q', 'quote'] exit_inputs = ['e', 'exit', 'quit'] view_inputs = ['v'] leader_board_inputs = ['l'] acceptable_inputs = buy_inputs \ +sell_inputs \ +lookup_inputs \ +quote_inputs \ +exit_inputs \ +view_inputs \ +leader_board_inputs user_input = view.main_menu() if user_input in acceptable_inputs: if user_input in buy_inputs: balance = model.check_balance(user_name) fee = 6.25 ticker_symbol = view.quote_menu() price = model.quote(ticker_symbol) trade_volume = view.transaction_menu(balance, ticker_symbol, price) transaction_cost = (float(trade_volume) * price) + fee if transaction_cost <= balance: balance -= transaction_cost model.update_cash(user_name, balance) model.buy(user_name, ticker_symbol, float(trade_volume), float(price)) model.buy_holdings(user_name, ticker_symbol, float(trade_volume), price) else: print("Not enough monay") elif user_input in sell_inputs: ticker_symbol = view.quote_menu() price = model.quote(ticker_symbol) trade_volume = view.sell_menu() owned = model.check_holdings(user_name, ticker_symbol) if owned and int(trade_volume) <= owned: model.sell_holdings(user_name, ticker_symbol, trade_volume, price, owned) else: print("You dont have that to sell") elif user_input in lookup_inputs: return model.lookup(view.lookup_menu()) elif user_input in quote_inputs: return model.quote(view.quote_menu()) elif user_input in exit_inputs: break elif user_input in leader_board_inputs or view_inputs: users = model.get_users() users_list = [ ] # this is a list of all the users that currenttly have holdings for i in users: users_list.append(i[0]) users_holdings = [ ] # users holdings by tickers but not numbers for i in users_list: user_holdings = model.get_holdings(i) a = [] for i in user_holdings: a.append(i[0]) users_holdings.append(a) tickers = [ ] # is all the stocks the users, un "set'd" and joinined together for i in users_holdings: for j in i: tickers.append(j) prices = { } # this has all the prices for all the stocks owned in the holdings for i in set(tickers): # price = model.quote(i) prices[i] = price volumes = [ ] # a list of lists of amount of stock each of them own for i in users_list: volumes.append(model.holdings_volumes(i)) values_final = {} for i in range(len(users_holdings)): total = 0 for j in range(len(users_holdings[i])): total += (prices[users_holdings[i][j]]) * ( volumes[i][j][0]) values_final[users_list[i]] = total highest = 0 sorted_words = {} while values_final: for i in values_final: if values_final[i] >= highest: highest = values_final[i] word = i sorted_words[word] = highest values_final.pop(i) highest = 0 if user_name[0:5] == 'admin': view.leader_board() for i in sorted_words: print("{} : {}".format(i, sorted_words[i])) balance = model.check_balance(user_name) view.show_balance(balance) for i in users_list: if i == user_name: index = users_list.index(i) x = users_holdings[index] y = volumes[index] for i in range(len(x)): amount = prices[x[i]] * y[i][0] print('{} : {}'.format(x[i], amount))