【问题标题】:python 3.2 printing tablespython 3.2 打印表格
【发布时间】:2012-10-16 01:32:04
【问题描述】:

我正在学习 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/

我完全不明白这是怎么回事。

【问题讨论】:

    标签: python-idle python-3.2


    【解决方案1】:

    第 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')。 写标题行

    第 3 步:有趣的循环

    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 上提问时,请您自己付出一点努力。否则你将不可能得到任何帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-20
      • 2021-12-31
      • 2015-11-06
      • 2013-10-24
      • 2015-12-12
      • 1970-01-01
      • 2011-11-13
      • 2011-07-04
      相关资源
      最近更新 更多