Python编程,一遍又一遍地获得相同的值而不是增加

标签 python

所以我正在为大学做作业,而且对编码还很陌生,所以这是问题。在一所大学,全日制学生的学费为每学期 8,000 美元。已宣布 future 五年学费每年上涨3%。编写一个带有循环的程序,“显示 future 五年预计的学期学费金额。”

tuition_increase = 0.03
tuition = 8000
tuition_total = 0
years = 5

print('tuition_total\tyears')
print('--------------------')
for years in range (1, years + 1)
    tuition_total = (tuition * tuition_increase) + tuition
    print(tuition_total, '/t', years)

我不断地获得相同的值,而不是随着每年学费的增加而增加

最佳答案

您没有将 tuition_total 值与上一步计算出的 tuition_total 值相加,请尝试以下方式。

tuition_total = ((tuition * tuition_increase) + tuition) + tuition_total

tuition_total += (tuition * tuition_increase) + tuition

关于Python编程,一遍又一遍地获得相同的值而不是增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50207076/

相关文章:

python - Django 从另一个包导入另一个文件

python - 在手写数字示例中使用 scikit-learn 实现 SVM 的特征提取器

python - 值错误 : dict contains fields not in fieldnames

退出整个程序时出现python线程异常错误

python - PyQt4中PYSIGNAL定义了什么模块

python - 编程式 Bokeh 服务器

python - Google Wave Robot/Python 变量问题

python - Debian 没有名为 numpy 的模块

python - 如何使用 genfromtxt 加载包含字符串和数字的 csv 文件?

python - 从 txt.file 读取时间戳并使用 matplotlib (Web 服务器)将它们绘制在 X 轴上