python 3.2打印表

时间:2012-10-16 01:32:05

标签: python-idle python-3.2

我正在学习Python并尝试编写程序,但我无法弄清楚应该如何编写它。

考虑到问题:

  

“使用功能”computeTax(status,taxableIncome):“编写一个程序,打印税收表的税表,从500美元到60000美元,所有四种状态的间隔为50美元,如下所示:

taxable income/   single/    married joint/   married seperate/   head of house/   
50000/             8688/       6665/              8688/               7352/  
50050/             8700/       6673/              8700/               7365/              
...                                                                  
59950/            11175/       8158/             11175/               9840/  
60000/            11188/       8165/             11188/               9852/

我不明白这是如何运作的。

1 个答案:

答案 0 :(得分:0)

第1步:税务计算

def computeTax(status,taxableIncome):
    """
    status is a string such as 'married joint', taxableIncome is the amount of income
    This function returns the portion of the income that should be paid as tax. This amount is different  depending on the status.
    """
    status_multupliers = {blah} #a dictionary of status to multiplier mappings...
    return taxableIncome * status_multipliers[status]

第2步:初始化你的文件:

打开文件进行书写('w')。 写下标题行

Step3:有趣的循环

for i in range(however_many_lines_you_want_in_your_table):
    income = 50*i #since we are going up in 50s
    current_line = ''     # this is what you want to write to your file
    for status in statuses: #statuses is a list of the available statuses. make this
        tax = computeTax(status,income)
        current_line += tax + '\'
    current_line += '\n'
    file.write(current_line)   #add the line

我认为格式化并不重要。

现在就在Stack Overflow上提问时,请自己动手一点。否则你不太可能得到任何帮助