用变量做计算
您已经创建了一个储蓄变量,现在开始存钱吧!
与其直接用具体数值计算,您也可以使用变量。
如果您每个月存 $10,那么从现在起 4 个月后,您将存下多少钱?
本练习是课程的一部分
Python 入门
练习说明
- 创建变量
monthly_savings,其值为10,以及变量num_months,其值为4。 - 将
monthly_savings乘以num_months,并将结果赋给new_savings。 - 打印
new_savings的值。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create the variables monthly_savings and num_months
# Multiply monthly_savings and num_months
new_savings = ____
# Print new_savings