以公司股票为背景,使用字符串格式化输出公司股票变化,具体要求如下:
"""
定义如下变量:
-name,公司名
-stock_price,当前股价
-stock_code, 股票代码
-stock_price_daily_growth_factor,股票每日增长系数,浮点数类型,比如1.2
-growth_days,增长天数
计算,经过growth_days天的增长后,股价达到了多少钱
使用字符串格式化进行输出,如果是浮点数,要求小数点精度2位数
"""
练习代码:
name = "大力出奇迹"
stock_price = 10.99
stock_code = 123666
stock_price_daily_growth_factor = 1.2
growth_days = 8
finally_stock_price = stock_price*(stock_price_daily_growth_factor **growth_days)
print(f"- 公司:{name},股票代码{stock_code},当前股价:¥{stock_price}")
print("- 每日增长系数:%.2f,经过%d天的增长后,股价达到了:¥%f" % (
stock_price_daily_growth_factor, growth_days,
finally_stock_price))
输出:
- 公司:大力出奇迹,股票代码123666,当前股价:¥10.99
- 每日增长系数:1.20,经过8天的增长后,股价达到了:¥47.254988