首页 > 解决方案 > print statement won't print value of my variable

问题描述

so I have this code to calculate the value of the variable chance and print it there are no error codes but when it gets to the print statement no matter what compiler I use to compile it nothing appears in the output

There is no error so I don't have anything to go off of

import math

luck = 54
justice = 0
compassion = 1
bravery = 1
truth = 2
coreType = "Legendary"
baseChance = 0.01
element = "Light"

import math
valid = True
if coreType == "Common":
    coreRarity = 1
elif coreType == "Rare":
    coreRarity = 1.5
elif coreType == "Legendary":
    coreRarity = 3
else:
    print("Invalid core type")
    valid = False

if justice > compassion and justice > truth and justice > bravery:
    idea = "justice"
elif compassion > justice and compassion > truth and compassion > bravery:
    idea = "compassion"
elif truth > compassion and truth > justice and truth > bravery:
    idea = truth
elif bravery > compassion and bravery > truth and bravery > justice:
    idea = "bravery"
else:
    idea = "all"

if idea == "justice" and (element == "Light" or element == "Shadow"):
    boost = justice
elif idea == "truth" and (element == "Ice" or element == "Wind"):
    boost = truth
elif idea == "compassion" and (element == "Earth" or element == "Lightning"):
    boost = compassion
elif idea == "bravery" and (element == "Fire" or element == "Water"):
    boost = bravery
elif idea == "all":
    boost = bravery #basicly the above determines what the highest idea is and sets it but if the highest is all it means they are all the same so It doesn't matter one one the boost's value is cause its all the same

if valid == True:
    chance = math.max(math.sqrt(luck*0.01*1.3)+0.95,1)*0.01*(0.01*(100+5*idea)*coreRarity*baseChance)
    if coreType == "common":
        chance =* 0.25
    print(chance)

It's supposed to print the value of chance but prints nothing

标签: python

解决方案


您的代码有两个问题:

  • chance =* 0.25应该是chance *= 0.25这里是所有assignmet运算符的列表)

  • 该模块math没有max属性,所以我建议您尝试max()而不是math.max()

那个beeing说尝试用这个替换你当前if的声明(最后的那个):

if valid == True:
    chance = max(math.sqrt(luck*0.01*1.3)+0.95,1)*0.01*(0.01*(100+5*idea)*coreRarity*baseChance)
    if coreType == "common":
        chance *= 0.25
    print(chance)

希望这可以帮助


推荐阅读