I am writing this code for class I have and I need some help adding exception handling. Basically what I need help with is fitting the exception handling around my user inputs so if the user inputs anything other than what is specified it'll loop back and ask the user to input the correct answer. I also need to have an exception handling with one of my functions. This is my code so far.
symbol_list = ['AAPL', 'AXP', 'BA', 'CAT', 'CVX', 'DIS', 'GS', 'HD', 'IBM', 'INTC']
price_list = [150.75, 98.65, 340.53, 129.77, 111.77, 111.42, 175.37, 177.89, 119.83, 47.74]
invest_dict = {'AAPL': 150.75, 'AXP': 98.65, 'BA':340.53, 'CAT' :129.77, 'CVX' :117.77, 'DIS' :111.42, 'GS':175.37, 'HD':177.89, 'IBM': 119.83, 'INTC':47.74}
print("...............................Lab 8.........................")
def Greeting():
print("The purpose of this project is to provide Stock Analysis.")
def Conversions(investment_amount):
investment_amount = float(investment_amount)
Euro = float(round(investment_amount / 1.113195,2) )
Pound = float(round(investment_amount / 1.262304,2) )
Rupee = float(round(investment_amount / 0.014316,2) )
print("The amount you invest in euro is: {:.2f}" .format(Euro) )
print("The amount you invest in pounds is: {:.2f}" .format(Pound) )
print("The amount you invested in Rupees is: {:.2f}" .format(Rupee) )
def minimum_stock():
key_min = min(invest_dict.keys(), key = (lambda k: invest_dict[k]))
print("The lowest stock you can buy is: ",invest_dict[key_min])
def maximum_stock():
key_max = max(invest_dict.keys(), key = (lambda k: invest_dict[k]))
print("The highest stock you may purchase is: ",invest_dict[key_max])
def invest_range(investment_amount):
new_list = []
new_list = [i for i in price_list if i>=50 and i <=200]
return(sorted(new_list))
answer = 'yes'
while answer:
print(Greeting())
investment_amount = float(input("Please enter the amount you want to invest:$ "))
if investment_amount!='':
print("Thank you for investing:$ {:,.2f}".format(investment_amount))
print(Conversions(investment_amount))
for i in invest_dict:
i = investment_amount
if i <25:
print("Not enough funds to purchase stock")
break
elif i>25 and i <=250:
print(minimum_stock())
break
elif i >= 250 and i <= 1000:
print(maximum_stock())
break
print("This is the range of stocks you may purchase: ", invest_range(investment_amount))
answer = input("Would you like to complete another conversion? yes/no " )
if answer == 'no':
print("Thank you for investing.")
break