【问题标题】:Can I compare 2 variables using if statement in python?我可以在 python 中使用 if 语句比较 2 个变量吗?
【发布时间】:2022-07-12 22:53:18
【问题描述】:

我正在尝试创建一个基本的日常费用跟踪器,并且我想使用 if 语句将总金额与费用进行比较,但我似乎无法为任何变量引入常量,我附上了快照并希望有任何协助

snapshot

【问题讨论】:

标签: python if-statement comparison


【解决方案1】:

需要将total_amount中的值相除

if money_left > total_amount / 2

或乘以 0.5:

if money_left > 1/2 * total_amount

【讨论】:

    【解决方案2】:

    您似乎想检查money_left 是否大于total_amount 的1/2。你可以这样做:

    if money_left > total_amount / 2:
       <insert print statement here>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-24
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多