# This client program tracks a user's purchases of two stocks, # computing and reporting which stock was more profitable. # It makes use of the Stock class, representing the user's # purchases of each unique stock as a Stock object. from Stock import * # make purchases of stock and return the profit def make_purchases(stock): num_purchases = int(input("How many purchases? ")) # ask about each purchase for i in range(num_purchases): shares = int(input(str(i + 1) + ": How many shares? ")) price = float(input(" Price per share? ")) # ask the Stock object to record this purchase stock.purchase(shares, price) # use the Stock object to compute profit current_price = float(input("Today's price per share? ")) profit = stock.profit(current_price) print("Net profit/loss: $", profit) print() return profit def main(): # create first stock symbol1 = input("First stock's symbol? ") stock1 = Stock(symbol1) profit1 = make_purchases(stock1) # create second stock symbol2 = input("Second stock's symbol? ") stock2 = Stock(symbol2) profit2 = make_purchases(stock2) # report which stock made more money if profit1 > profit2: print(symbol1, "was more profitable than", symbol2) elif profit2 > profit1: print(symbol2, "was more profitable than", symbol1) else: print(symbol1, "and", symbol2, "are equally profitable") main()