如何在main函数中打印函数

时间:2017-02-09 17:01:56

标签: python concatenation main

import math

return def is_valid(filing_status,income):

  """Function determines whether the input is valid. If valid, it returns 'True'. The filing status must come from the list of options given and the income must be an integer greater than 0. If these qualifications are not met, the function will return 'False'.""" 

   x = filing_status
   y = income
   def setup(x, y):
   if x in ('single', 'married filing jointly', 'married filing separately', 'widow', 'head of household') and y >= 0:
    print "True"
   else:
    print "False"
   setup(x, y)

return def tax(filing_status, income):

"""Fuction displays the value of taxes that different groups of people are required to pay based on their income."""

  f = filing_status
  i = income
  def calculation(f, i):
  if f in ('single') and int(0 < i <= 9275):
     print int(i*0.100)
  elif 9276 <= i <= 37650:
     print int((i-9276.00)*0.15 + 9275.*0.1)
  elif 37651 <= i <= 91150:
     print int((i-37651)*0.25 + 28375*0.15 + 9275*0.1)
  elif 91151 <= i <= 190150:
     print int((i-91151)*0.28 + 53500*0.25 + 28375*0.15 + 9275*0.1)
  elif 190151 <= i <= 413350:
     print int((i-190151)*0.33 + 99000*0.28 + 53500*0.25 + 28375*0.15 + 9275*0.1)
  elif 413351 <= i <= 415050:
     print int((i-413351)*0.35 + 223200*0.33 + 99000*0.28 + 53500*0.25 + 28375*0.15 + 9275*0.1)
  elif i >= 415051:
     print int((i-415051)*0.396 + 1700*0.35 + 223200*0.33 + 99000*0.28 + 53500*0.25 + 28375*0.15 + 9275*0.1)
  calculation(f,i)

 return def tax(filing_status,income):
 c = filing_status
 d = income
   def calculation(c,d):
   if c in ('widow','married filing jointly') and 0 < d <= 18550:
     print int(d*0.1)
   elif 18551 <= d <= 75300:
     print int((d-18551)*0.15 + 18550*0.1)
   elif 75301 <= d <= 151900:
     print int((d-75301)*0.25 + 56750*0.15 + 18550*0.1)
   elif 151901 <= d <= 231450:
     print int((d-151901)*0.28 + 76600*0.25 + 56750*0.15 + 18550*0.1)
   elif 231451 <= d <= 413350:
     print int((d-231451)*0.33 + 79550*0.28 +76600*0.25 + 56750*0.15 + 18550*0.1)
   elif 413351 <= d <= 466950:
     print int((d-413351)*0.35 + 181900*0.33 + 79550*0.28 +76600*0.25 + 56750*0.15 + 18550*0.1)
   elif d >= 466951:
     print int((d-466951)*0.396 + 53600*0.35 + 181900*0.33 + 79550*0.28 +76600*0.25 + 56750*0.15 + 18550*0.1)
  calculation(c,d)

return def tax(filing_status,income):
  g = filing_status
  h = income
  def calculation(g,h):
    if g in ('married filing separately') and 0 < h <= 9275:
       print int(h*0.1)
    elif 9276 <= h <= 37650:
       print int((h-9276)*0.15 + 9275*0.1)
    elif 37651 <= h <= 75950:
       print int((h-37651)*0.25 + 28375*0.15 + 9275*0.1)
    elif 75951 <= h <= 115725:
       print int((h-75951)*0.28 + 38300*0.25 + 28375*0.15 + 9275*0.1)
    elif 115726 <= h <= 206675:
       print int((h-115726)*0.33 + 39775*0.28 +38300*0.25 + 28375*0.15 + 9275*0.1)
    elif 206676 <= h <= 233475:
       print int((h-206676)*0.35 + 90950*0.33 + 39775*0.28 +38300*0.25 + 28375*0.15 + 9275*0.1)
    elif h >= 233476:
       print int((h-233476)*0.396 + 26800*0.35 + 90950*0.33 + 39775*0.28 +38300*0.25 + 28375*0.15 + 9275*0.1)

    calculation(g,h)

return def tax(filing_status,income):
    m = filing_status
    n = income
    def calculation(m,n):
       if m in ('head of household') and 0 < n <= 13250:
          print int(n*0.1)
       elif 13251 <= n <= 50400:
          print int((n-13251)*0.15 + 13250*0.1)
       elif 50401 <= n <= 130150:
          print int((n-50401)*0.25 + 37150*0.15 + 13250*0.1)
       elif 130151 <= n <= 210800:
          print int((n-130151)*0.28 + 79750*0.25 + 37150*0.15 + 13250*0.1)
       elif 210801 <= n <= 413350:
          print int((n-210801)*0.33 + 80649*0.28 +79750*0.25 + 37150*0.15 + 13250*0.1)
       elif 413351 <= n <= 441000:
          print int((n-413351)*0.35 + 202550*0.33 + 80649*0.28 +79750*0.25 + 37150*0.15 + 13250*0.1)
       elif n >= 441001:
          print int((n-441001)*0.396 + 27649*0.35 + 202550*0.33 + 80649*0.28 +79750*0.25 + 37150*0.15 + 13250*0.1)

      calculation(m,n)

return def percent_of_income(tax, income):
   """Function calculates the percent of income that goes to taxes."""

    t = tax
    s = income
    def calc_percent (t, s):
       print (t/s)*100
    calc_percent(t, s)

return def main(filing_status,income):
  """Function brings the previous functions together to describe taxes and the percent of income of individuals based on their filing statuses"""

  w = filing_status
  o = income
  v = tax(filing_status, income)
  if w not in ('single', 'married filing jointly', 'married filing separately', 'widow', 'head of household'): 
     print "Invalid input. Filing status must be 'single', 'married filing jointly', 'married filing separately', 'widow', or 'head of household'. Income must be greater than or equal to zero."
  if o < 0: 
     print "Income must be greater than or equal to zero." 
  else:
     return ('Tax: $', str(v))
     return ('Tax as % of income: $', str(percent_of_income(tax, income)) + '%')

尝试在主要内容中打印税收和百分比的收入函数。我该如何参考?我不确定收入百分比中的变量是否记录正确,每次我尝试运行该函数时,都不会在字符串“Tax;”中打印税值。我也试过连接它。

1 个答案:

答案 0 :(得分:0)

我想我需要更多信息来帮助你,但我会尝试。

使用此功能看起来只有在执行第一个或第二个if时才打印。如果不是,则执行else,它只返回一个元组而不打印。此外,第二次返回将不会执行。执行返回后,函数结束。