# 股价计算小程序
"""
定义如下变量:
name,公司名
stock_price,当前股价
stock_code,股票代码
stock_price_daily_growth_factor,股票每日增长系数,浮点数类型,1.2
growth_days,增长天数
请计算,经过growth_days天的增长后,股价达到了多少钱
使用字符串格式化进行输出,如果是浮点数,要求小数点精度2位数。
公司:臭八十的 股票代码:5201314 当前股价:19.99 本行用f"(变量)"输出
每日增长系数:1.2,经过7天增长后,股价达到了多少钱? 本行用%占位符输出
"""
name = "臭八十的"
stock_price = 19.99
stock_code = 5201314 # 数字不能以0开头赋值变量,需要"001234"
stock_price_daily_growth_factor = 1.2
growth_days = 7
print(f"公司:{name},股票代码:{stock_code},当前股价:{stock_price}")
print("每日增长系数为:%.2f,经过%d天增长后,股价为%.2f."%(stock_price_daily_growth_factor,
growth_days,stock_price*stock_price_daily_growth_factor**growth_days))
运行后显示结果:
公司:臭八十的,股票代码:5201314,当前股价:19.99
每日增长系数为:1.20,经过7天增长后,股价为71.63.
进程已结束,退出代码为 0

被折叠的 条评论
为什么被折叠?



