检查特定类是否在列表中

huangapple go评论130阅读模式
英文:

Checking if a certain class is in a list

问题

我正在尝试在 list_of_status 中检测到 "Burn" 时将 lps_multiplier 乘以 1.2,而在未检测到 "Burn" 时将 lps_multiplier 除以 1.2,但以下代码同时运行 if 语句和 else 语句。

  1. list_of_status = []
  2. list_of_status.append(StatusEffect(name="Burn", amount=999))
  3. list_of_status.append(StatusEffect(name="Testing Status", amount=1, timed=300))
  4. for l in reversed(range(0, len(list_of_status)):
  5. BurnCheck = list_of_status[l]
  6. BurnCheck = BurnCheck.name
  7. if "Burn" in [BurnCheck]:
  8. if lps_multiplier < 1.2:
  9. lps_multiplier *= 1.2
  10. updateTotalLPS(list_of_buildings)
  11. else:
  12. lps_multiplier /= 1.2
  13. updateTotalLPS(list_of_buildings)
  14. print(lps_multiplier)
英文:

I am trying to make it so lps_multipler gets mutiplied by 1.2 when burn is detected in list_of_status, and dividng lps_multipler by 1.2 when burn is not detected. but the following code runs the else statement aswell as the if statement at the same time.

  1. list_of_status = []
  2. list_of_status.append(StatusEffect(name=&quot;Burn&quot;, amount=999))
  3. list_of_status.append(StatusEffect(name=&quot;Testing Status&quot;, amount=1, timed=300))
  4. for l in reversed( range(0, len(list_of_status)) ):
  5. BurnCheck = list_of_status[l]
  6. BurnCheck = BurnCheck.name
  7. if &quot;Burn&quot; in [BurnCheck]:
  8. if lps_multiplier &lt; 1.2:
  9. lps_multiplier *= 1.2
  10. updateTotalLPS(list_of_buildings)
  11. else:
  12. lps_multiplier /= 1.2
  13. updateTotalLPS(list_of_buildings)
  14. print(lps_multiplier)

答案1

得分: 1

调试步骤

尝试添加以下打印语句,并将结果反馈回来,将它们作为文本粘贴在问题中(不是作为图像)。

  1. for l in reversed(range(0, len(list_of_status))):
  2. BurnCheck = list_of_status[l]
  3. BurnCheck = BurnCheck.name
  4. print(f"l is {l}, lps_multiplier is {lps_multiplier}")
  5. if "Burn" in [BurnCheck]:
  6. print(" Burn found")
  7. if lps_multiplier < 1.2:
  8. lps_multiplier *= 1.2
  9. print(" LPS being multiplied")
  10. updateTotalLPS(list_of_buildings)
  11. else:
  12. print(" Burn not found")
  13. lps_multiplier /= 1.2
  14. print(" LPS being divided")
  15. updateTotalLPS(list_of_buildings)
  16. print(lps_multiplier)
英文:

Debugging steps

Try adding these print statements and reporting back the results by pasting them in as text in the question (not an image).

  1. for l in reversed( range(0, len(list_of_status)) ):
  2. BurnCheck = list_of_status[l]
  3. BurnCheck = BurnCheck.name
  4. print(f&quot;l is {l}, lps_multiplier is {lps_multiplier}&quot;)
  5. if &quot;Burn&quot; in [BurnCheck]:
  6. print(&quot; Burn found&quot;)
  7. if lps_multiplier &lt; 1.2:
  8. lps_multiplier *= 1.2
  9. print(&quot; LPS being multplied&quot;)
  10. updateTotalLPS(list_of_buildings)
  11. else:
  12. print(&quot; Burn not found&quot;)
  13. lps_multiplier /= 1.2
  14. print(&quot; LPS being divided&quot;)
  15. updateTotalLPS(list_of_buildings)
  16. print(lps_multiplier)
  17. </details>

huangapple
  • 本文由 发表于 2023年3月12日 09:33:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定