-1

我正在学习 Python 并尝试编写程序,但我不知道应该如何编写它。

鉴于问题:

"使用函数 "computeTax(status, taxableIncome):" 编写一个程序,打印一个从 $50000 到 $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/

我根本不明白这是如何工作的。

4

1 回答 1

0

Step 1: The tax computation

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]

Step2: initialise your file:

open a file for writing ('w'). write the heading line

Step3: fun with loops

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

I've assumed that formatting doesn't matter too much.

For now on when asking questions on Stack Overflow please show a little bit of effort yourself. Otherwise you will be unlikely to get any help

于 2012-10-22T12:54:44.593 回答