Wolfram 语言

云端和网络界面

创建网路表单来计算边际税率

在很多情况下,涉及纳税的计算太过复杂,难以有效地嵌入到单独的一个网络表单中. AskFunction 可使你以简单而直观的方式进行计算.

In[1]:=
Click for copyable input
CloudDeploy[AskFunction[Module[{bracket, tax, income}, bracket = Ask[{"brackets", "What is your marital status?"} -> {"Married filing jointly" \ -> {18550, 75300, 151900, 231450, 413350, 466950}, "Single" -> {9275, 37650, 91150, 190150, 413350, 415050}, "Head of household" -> {13250, 50400, 130150, 210800, 413350, 441000}, "Married filing separately" -> {9275, 37650, 75950, 115725, 206675, 233475}}]; income = Ask[{"income", "What was your income in 2015"} -> Restricted["Number", {0, Infinity}]]; tax = Integrate[ Piecewise[{{.10 , 0 <= x <= bracket[[1]]}, {.15, bracket[[1]] < x <= bracket[[2]]}, {.25, bracket[[2]] < x <= bracket[[3]]}, {.28, bracket[[3]] < x <= bracket[[4]]}, {.33, bracket[[4]] < x <= bracket[[5]]}, {.35, bracket[[5]] < x <= bracket[[6]]}, {.396, True}}], {x, 0, income - If[Ask[{"deps", "Do you have any dependents?"} -> {"Yes" -> True, "No" -> False}], Ask[{"nodeps", "How many?"} -> Restricted["Integer", {0, Infinity}]]* 4050, 0]}]; AskTemplateDisplay[ Column[{"You owe $" <> ToString[tax] <> " in taxes.", "Your marginal tax rate is " <> ToString[Round[100.*tax/#income, 0.1]] <> "%", PieChart[{tax, income}]}] &] ]]]
Out[1]=

从本例中可以看到,你可以使用自己喜欢的编程风格,包括 Module 的应用以及对计算状态的存储. 此外,AskFunction 会跳过不需要的问题. 可以自己尝试一下.

相关范例

de en es fr ja ko pt-br ru