股价计算小程序

定义如下变量:

  • name,公司名
  • stock_price,当前股价
  • stock_code,股票代码
  • stock_price_daily ,股票每日增长系数,浮点数类型,
  • growth_days , 增长天数

计算,经过growth_days天的增长后,股价达到了多少

使用字符串格式化输出,如果是浮点数,要求小数点精度2位数

 

 最终股价 = 当前股价 * 增长系数 **增长天数

1 name = "传智播客"
2 stock_code = "003032"
3 stock_price = 19.99
4 stock_price_daily = 1.2
5 growth_days = 7
6 print(f"公司:{name},股票代码{stock_code},当前股价{stock_price}")
7 result = stock_price * stock_price_daily ** growth_days
8 print("每日增长系数是:%.2f,经过%d天的增长后,股价达到了:%.2f" %(stock_price_daily, growth_days, result))

 

posted @ 2023-03-04 16:44  摆烂小T  阅读(589)  评论(0)    收藏  举报