以表格格式编写一个显示薪资计划的程序, 适用于学区的教师。输入是起薪, 增加的百分比,以及时间表中的年数。每 时间表中的行应包含年份编号和工资 那年。起始金额为30,000美元,比上一年增加2% 10年的历程。
到目前为止,我有这个:
startSalary = int(input("Enter start salary: "))
percentIncrease = (float(input("Enter percent increase: "))/ 100)
numberYears = list(range(1,(int(input("Enter number of years in the schedule: ")) +1 )))
def calculateSalary(startSalary, percentIncrease, numberYears):
for year in numberYears:
salaryIncrease = startSalary * percentIncrease
newSalary = startSalary + salaryIncrease
startSalary = newSalary
print(year, newSalary)
calculateSalary(startSalary, percentIncrease, numberYears)
当我运行代码时这很好用,但是对于我的起始年份它运行30,600并且我需要它从30,000开始(因此它是起薪)。
答案 0 :(得分:0)
尝试一下,如果您还没有解决的话。
startSalary = int(input(" enter beginning salary: "))
percentIncrease = (float(input(" enter percentage increase: ")) / 100)
numberYears = list(range(1,(int(input(" enter number of years in schedule: "))+1)))
def calculateSalary(startSalary, percentIncrease, numberYears):
for year in numberYears:
salaryIncrease = startSalary * percentIncrease
newSalary = startSalary + salaryIncrease
print("{} {:0.2f}".format(year, startSalary))
startSalary = newSalary
calculateSalary(startSalary, percentIncrease, numberYears)
答案 1 :(得分:0)
from tabulate import tabulate
a = ['year', 'salary']
b = [[i+1, 30000*(1.02**i)] for i in range(10)]
print(tabulate(b, a))
year salary
------ --------
1 30000
2 30600
3 31212
4 31836.2
5 32473
6 33122.4
7 33784.9
8 34460.6
9 35149.8
10 35852.8