python - 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
解决方案
您的代码有两个问题:
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)
希望这可以帮助
推荐阅读
- class - 如何编写对另一个类的状态的 puppet 类依赖
- javascript - 如何使用 axios get 方法获取 onDownloadProgress 百分比?
- java - 带有前缀的 UUID 的 Java 正则表达式
- ruby-on-rails - Rails 迁移添加了一个 null: false 列,其初始值不是持续的默认值
- ios - 是否有某种包装器可以让蓝牙与网络应用程序通信?当然使用本机构建来保存包装器
- java - 使用 Spring Boot 在运行时以编程方式更改 application.properties 文件
- regex - 比较两个文件而不对 AWK 进行排序
- ios - 如何使用 Xcode 在 Launchscreen.storyboard 中为 UILabel 指定“等宽系统字体”?
- django - 无法在 Django 中将当前用户设置为帖子的作者
- android - 为什么 iOS Safari 浏览器中的 padding 和 margin 看起来不同?