【发布时间】:2017-11-04 17:51:08
【问题描述】:
目标
我的目标是拥有 3 个股票列表,并根据用户输入的匹配值显示每个列表的相同索引位置。
我的 3 个列表
Price = [37.10, 46.18, 51.76, 145.64]
Symbol = ['T', 'KO', 'ABQ', 'LOW']
Name = ['ATT', 'COCA COLA COMPANY', 'ABBOT LABORATORIES', 'LOWES COMPANY INC']
我的完整脚本会要求用户提供investment amount and if below $1000 it'll invest in the cheapest stock。
If over $1000, it'll invest in the most expensive stock.
所以if under $1000, it should invest all the money into ATT at $37.10 per share。
如果over $1000, it should invest all the money into LOW at $145.64 a share.
输出应显示其投资的给定股票的股票购买量。
输出给用户
您今天想投资多少? 1001.57
以下是可供购买的库存:
Price | Symbol | Name
$ 37.1 | T | ATT
$ 46.18 | KO | COCA COLA COMPANY
$ 51.76 | ABT | ABBOTT LABORATORIES
$ 145.64 | LOW | LOWES COMPANIES INC
这将以每股 37.1 美元的价格购买 26.99 股“T:ATT”。
这将以每股 145.64 美元的价格购买 6.87 股“LOW:LOWES COMPANIES INC”。
我的代码如下:
investing = (float(input("How much are you wanting to invest today? ")))
print ("\nBelow are the stocks available for purchase:")
print ("\nLast Trade | Symbol | Name ")
for pr, sy, na, in sorted(zip(stock_price, stock_symbol, stock_name)):
print ('$',pr, '|',sy, '|',na)
cheapest_stock = (min(stock_price))
expensive_stock = (max(stock_price))
purchase_low = (investing/cheapest_stock) // 0.01 / 100
purchase_hi = (investing/expensive_stock) // 0.01 / 100
print (f"\nThis will purchase {purchase_amt} shares of 'T:ATT' at ${cheapest_stock} per share.")
print (f"\nThis will purchase {purchase_amt} shares of 'LOW:ATT' at ${expensive_stock} per share.")
问题
我不知道如何获得由min(stock_price) 确定的低值或由max(stock_price) 确定的高值以显示其他列表中股票代码和股票名称的匹配值。
所以我目前在上面的打印语句中手动输入了它。
【问题讨论】:
-
非常感谢!效果很好!
-
如果答案对你有帮助,别忘了将答案标记为“已接受答案”
标签: python-3.x