代码:从代码界面就开始提示报错
运行报错:TypeError: unsupported operand type(s) for ** or pow(): 'tuple' and 'tuple'
后来发现是在定义变量时在后面加了逗号,将逗号去掉之后,问题解决
原因应该是将逗号也一起赋值给了变量了,然后将浮点型或者整数型转换成了字符串,导致后面无法计算。
源代码:
name = "天珑"
stock_price = 19.99
stock_code = "302659"
stock_price_daily_growth_factor = 2.5
growth_days = 12
final_stock_price = stock_price * stock_price_daily_growth_factor ** growth_days
print(f"公司:{name},股票代码:{stock_code},当前股价:{stock_price}")
print("每日增长系数:%f,经过%d天的增长后,股价达到了:%.2f钱" % (stock_price_daily_growth_factor, growth_days, final_stock_price))