Names = {} Prices = {} Exposure = {} symbol = input(\'What is the stock symbol?\
ID: 3714339 • Letter: N
Question
Names = {}
Prices = {}
Exposure = {}
symbol = input('What is the stock symbol?')
def addName():
name_symbol = input('What is the name?')
Names[name_symbol] = symbol
def addPrices():
buyPrice = input('What is the buy price?')
currentPrice = input('What is the current price?')
Prices[buyPrice] = currentPrice
def addExposure():
risk = input('What is the current risk of the stock?')
shares = input('What is the current shares of the stock?')
Exposure[risk] = shares
def main():
name1, name2 = input('Please enter two more stock names.').split()
buyPrice1, buyPrice2 = input('Please enter two more buy prices for each corresponding name').split()
price1, price2 = input('Please enter two more current prices for each corresponding name.').split()
risk1 , risk2 = input('Please enter two more risk chances for each corresponding name.').split()
exposure1, exposure2 = input('Please enter two more shares for each corresponding name.').split()
Names[name1] = name2
Prices[buyPrice1] = price1
Prices[buyPrice2] = price2
Exposure[exposure1]= risk1
Exposure[exposure2] = risk2
def addStock():
addName()
addPrices()
addExposure()
main()
addStock()
print(Names)
print(Prices)
print(Exposure)
using this code that i coded can someone help me with part 2 please.
Note! Your program does not need to check for valid floating point user input; if the program crashes because of this no points will be deducted. However, there is code below that you may use to validate input to be sure that the input is valid.
First, you will need to add the following function:
GetSale - Finds the maximum expected value of selling a stock. The expected sale value of a stock is the current profit minus the future value of the stock:
Expected Sale value = ( ( Current Price - Buy Price ) - Risk * CurrentPrice ) * Shares
The GetSale function should calculate this value for each stock in the portfolio, and return the stock symbol with the highest expected sale value.
Main - Change/update/add the main function. This should take no arguments, but present a menu item consisting of "1. Add Stock", "2. Recommend Sale" and "3. Exit". If the user selects '1,' the Add Stock function is called, and when it is complete, the menu is presented again. If the user selects '2,' the Symbol of the stock corresponding to the highest expected value (returned by GetSale) should be displayed, and the menu presented after completion. If the user selects '3', the program should end.
Be sure to use comments for both structure of the program and documentation of the code.
All code must completely be your own individual work product.
Explanation / Answer
Names = {} Prices = {} Exposure = {} symbol = input('What is the stock symbol?') def addName(): name_symbol = input('What is the name?') Names[name_symbol] = symbol def addPrices(): buyPrice = input('What is the buy price?') currentPrice = input('What is the current price?') Prices[buyPrice] = currentPrice def addExposure(): risk = input('What is the current risk of the stock?') shares = input('What is the current shares of the stock?') Exposure[risk] = shares def addStock(): addName() addPrices() addExposure() def GetSale(): maxexp = 0 for (k1,v1), (k2,v2) in zip(Prices.items(), Exposure.items()): exp = ((v1 - k1) - k2 * v1) * v2 if exp > maxexp: maxexp = exp return maxexp def main(): while True: print("1. Add Stock") print("2. Recommend Sale" ) print("3. Exit") inp = int(input("Enter your choice")) if inp == 1: addStock() elif inp == 2: GetSale() else: return main() print(Names) print(Prices) print(Exposure)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.