-1

私はPythonを学んでおり、プログラムを書こうとしていますが、どのように書けばよいかわかりません。

問題を考えると:

次のように、「関数 "computeTax(status, taxableIncome):" を使用して、50000 ドルから 60000 ドルまでの課税所得の税表を 4 つのステータスすべてについて 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

ステップ 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 で質問するときは、少し努力してみてください。そうでなければ、あなたは何の助けも得られないでしょう

于 2012-10-22T12:54:44.593 に答える