如何进行薪酬控制报表?(Python)

2024-09-30 00:41:42 发布

您现在位置:Python中文网/ 问答频道 /正文

Write a program that displays a salary schedule, in tabular format, for teachers in a school district. The inputs are the starting salary, the percentage increase, and the number of years in the schedule. Each row in the schedule should contain the year number and the salary for that year. The starting amount is $30,000, increases by 2% over the course of 10 years.

到目前为止,我有这个:

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)

当我运行代码时,这个工作很好,但是对于我的起始年,它是30600,我需要它从30000开始(这就是为什么它是起薪)。在


Tags: oftheinnumberforinputyearschedule
2条回答
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

试试这个,如果你还没有解决它。在

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)

相关问题 更多 >

    热门问题