num1 = 11
num2 = 11.345
print("数字11宽度限制为5,结果%5d" % num1)
print("数字11宽度限制为1,结果%1d" % num1)
print("数字11.345宽度限制为7,小数精度为2结果%7.2f" % num2)
print("数字11.345不限制宽度限制,小数精度为2结果%.2f" % num2)
name = "吱昂张"
stock_price = 19.99
stock_code = "003032"
stock_price_daily_growth_factor = 1.2
growth_days = 7
# 计算经过7天后,股价达到了多少钱?
finally_stock_price = stock_price * stock_price_daily_growth_factor ** growth_days
print(f"公司:{name} 股票代码:{stock_code} 当前股价{stock_price}")
print("每日的增长系数是%.1f,经过%d天的增长后,股价达到了:%.2f" % (stock_price_daily_growth_factor, growth_days,finally_stock_price))
?
运行代码如下: