【发布时间】:2022-01-19 19:34:25
【问题描述】:
if type(satisfaction) != int or type(satisfaction) != float:
raise TypeError('The type of satisfaction is not ok')
这是班级的__init__
def __init__(self, minibar, floor, number,
guests, clean_level, rank, satisfaction=1.0):
那些价值观
rooms = [Room(m, 15, 140, [], 1, 1), Room(m, 12, 101, ["Ronen", "Shir"], 6, 2),
Room(m, 2, 2, ["Liat"], 1, 1), Room(m, 2, 23, [], 1, 1)]
它会引发错误
raise TypeError('The type of satisfaction is not ok')
TypeError: The type of satisfaction is not ok
有什么问题?
【问题讨论】:
-
当您使用
or时,该陈述将始终为真...您的意思是and。但请在未来始终提供minimal reproducible example -
注意,这可能是你脑中对德摩根定律的误用,这是一个常见的错误。你做了
not ( x or y)->(not x) or (not y),但它应该是not ( x or y)->(not x) and (not y),当你分配否定(not)它在一个连词(or) and a disjunction (and`)之间翻转,反之亦然跨度>
标签: python class exception typeerror