检查特定类是否在列表中

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

Checking if a certain class is in a list

问题

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

list_of_status = []
list_of_status.append(StatusEffect(name="Burn", amount=999))
list_of_status.append(StatusEffect(name="Testing Status", amount=1, timed=300))

for l in reversed(range(0, len(list_of_status)):
    BurnCheck = list_of_status[l]
    BurnCheck = BurnCheck.name
    if "Burn" in [BurnCheck]:
        if lps_multiplier < 1.2:
            lps_multiplier *= 1.2
            updateTotalLPS(list_of_buildings)
    else:
        lps_multiplier /= 1.2
        updateTotalLPS(list_of_buildings)
    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.

    list_of_status = []
    list_of_status.append(StatusEffect(name=&quot;Burn&quot;, amount=999))
    list_of_status.append(StatusEffect(name=&quot;Testing Status&quot;, amount=1, timed=300))

    
for l in reversed( range(0, len(list_of_status)) ):
                BurnCheck = list_of_status[l]
                BurnCheck = BurnCheck.name
                if &quot;Burn&quot; in [BurnCheck]:
                    if lps_multiplier &lt; 1.2:
                        lps_multiplier *= 1.2
                        updateTotalLPS(list_of_buildings)
                else:
                    lps_multiplier /= 1.2
                    updateTotalLPS(list_of_buildings)
                print(lps_multiplier)

答案1

得分: 1

调试步骤

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

for l in reversed(range(0, len(list_of_status))):
    BurnCheck = list_of_status[l]
    BurnCheck = BurnCheck.name
    
    print(f"l is {l}, lps_multiplier is {lps_multiplier}")

    if "Burn" in [BurnCheck]:
        
        print("  Burn found")

        if lps_multiplier < 1.2:
            lps_multiplier *= 1.2

            print("    LPS being multiplied")

            updateTotalLPS(list_of_buildings)
    else:

        print("  Burn not found")

        lps_multiplier /= 1.2

        print("    LPS being divided")

        updateTotalLPS(list_of_buildings)
    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).

for l in reversed( range(0, len(list_of_status)) ):
                BurnCheck = list_of_status[l]
                BurnCheck = BurnCheck.name
                
                print(f&quot;l is {l}, lps_multiplier is {lps_multiplier}&quot;)

                if &quot;Burn&quot; in [BurnCheck]:
                    
                    print(&quot;  Burn found&quot;)

                    if lps_multiplier &lt; 1.2:
                        lps_multiplier *= 1.2

                        print(&quot;    LPS being multplied&quot;)

                        updateTotalLPS(list_of_buildings)
                else:

                    print(&quot;  Burn not found&quot;)

                    lps_multiplier /= 1.2

                    print(&quot;    LPS being divided&quot;)

                    updateTotalLPS(list_of_buildings)
                print(lps_multiplier)

</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:

确定