当前位置: 代码迷 >> python >> 如何在主功能中打印功能
  详细解决方案

如何在主功能中打印功能

热度:56   发布时间:2023-06-13 14:18:47.0
import math

返回def is_valid(filing_status,收入):

  """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;”内打印税值。 我也尝试将其串联。

我想我需要更多信息来帮助您,但我会尽力的。

使用此功能,您似乎仅在执行第一个或第二个if的情况下才进行打印。 如果不是,则您正在执行else,这将仅返回一个元组而不打印。 同样,将不执行第二次返回。 一旦执行返回,函数便结束。

  相关解决方案