【问题标题】:How to add an integer to this sentence?如何在这句话中添加一个整数?
【发布时间】:2020-10-21 04:06:10
【问题描述】:

我正在尝试让 python 运行一个看起来像这样的语句。

"How much did you make this year: " #Enter amount here in cash

"Expect to pay (4% of your amount in cash) in taxes this year."

【问题讨论】:

标签: python integer conditional-statements multiplication money-format


【解决方案1】:

您可以使用以下代码:

pay = int(input("How much did you make this year:"))
print(f"Expect to pay {pay * 0.04} in taxes this year.")

【讨论】:

  • 不应该是0.04吗?
  • @Selcuk 是的,感谢您指出(修复了错误)。
  • @longanddog 如果有帮助,请不要忘记点击旁边的复选标记来接受答案。
【解决方案2】:

val = input("你今年赚了多少钱:")

print("预计今年要缴纳 "+str(0.04*float(val))+ " 税款。")

【讨论】:

  • 在 Python 中不赞成使用 + 连接字符串。
猜你喜欢
  • 2013-05-11
  • 1970-01-01
  • 2021-03-31
  • 2012-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
相关资源
最近更新 更多