# # ps6pr4.py (Problem Set 6, Problem 4) # # TT Securities # # Computer Science 111 # def display_menu(): """ prints a menu of options """ print() print('(0) Input a new list of prices') print('(1) Print the current prices') print('(2) Find the latest price') ## Add the new menu options here. print('(8) Quit') def get_new_prices(): """ gets a new list of prices from the user and returns it """ new_price_list = eval(input('Enter a new list of prices: ')) return new_price_list def print_prices(prices): """ prints the current list of prices input: prices is a list of 1 or more numbers. """ if len(prices) == 0: print('No prices have been entered.') return print('Day Price') print('--- -----') for i in range(len(prices)): print('%3d' % i, end='') print('%6.2f' % prices[i]) def latest_price(prices): """ returns the latest (i.e., last) price in a list of prices. input: prices is a list of 1 or more numbers. """ return prices[-1] ## Add your functions for options 3-7 below. def tts(): """ the main user-interaction loop """ prices = [] while True: display_menu() choice = int(input('Enter your choice: ')) print() if choice == 0: prices = get_new_prices() elif choice == 8: break elif choice < 8 and len(prices) == 0: print('You must enter some prices first.') elif choice == 1: print_prices(prices) elif choice == 2: latest = latest_price(prices) print('The latest price is', latest) ## add code to process the other choices here else: print('Invalid choice. Please try again.') print('See you yesterday!')