[英]How can I suppress output in Python?
My assignment has 3 values in the defined function and those 3 values are Reactors.我的作业在定义的 function 中有 3 个值,这 3 个值是反应堆。 One condition in the assignment states that " Do not display information about mixing time if a given reactor is not used in production (eg if x3=0 the message about the third reactor will not be displayed)."
作业中的一个条件是“如果给定反应器未用于生产,则不显示有关混合时间的信息(例如,如果 x3=0,则不会显示有关第三个反应器的消息)。”
def Report2(x1,x2,x3):
if x1==0:
return None
if x2==0:
return None
if x3==0:
return None
y=mixing(x1)+mixing(x2)+mixing(x3)
return y
this is my code as of the moment, the problem is that whenever i assign the values (0,0,0) and print I get the word None.这是我目前的代码,问题是每当我分配值(0,0,0)并打印时,我都会得到None这个词。 What I want is for nothing to be displayed instead.
我想要的是什么都不显示。
Thank you谢谢
Store the result and print in a conditional.存储结果并在条件中打印。
result = Report2(0,0,0)
if result:
# will not execute if result == None
print(result)
You just need to use condition after the function executed:您只需要在 function 执行后使用条件:
def Report2(x1,x2,x3):
if x1==0 or x2==0 or x3==0:
return None
y=mixing(x1)+mixing(x2)+mixing(x3)
return y
result = Report2(0,0,0)
if result:
print(result)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.