2012-10-16 89 views
-1

我正在學習Python並試圖編寫一個程序,但我無法弄清楚如何編寫它。python 3.2打印表

鑑於問題:

「使用功能‘computeTax(狀態,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/ 

我不明白這是如何工作的所有

回答

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] 

第二步:初始化文件:

打開一個文件寫( 'W')。 寫標題行

第三步:樂趣循環

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上提出問題時,請您自己展示一些功夫。否則你將不可能得到任何幫助