2012-10-16 59 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上提出问题时,请您自己展示一些功夫。否则你将不可能得到任何帮助