英文:
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="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)
答案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"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 multplied")
updateTotalLPS(list_of_buildings)
else:
print(" Burn not found")
lps_multiplier /= 1.2
print(" LPS being divided")
updateTotalLPS(list_of_buildings)
print(lps_multiplier)
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论