From eaaf7576121255827069a95dee49f86e565e6003 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sat, 12 Feb 2022 10:08:44 -0500 Subject: [PATCH] [F] Fix prep6 --- practice/prep6.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/practice/prep6.py b/practice/prep6.py index a201501..20d2417 100755 --- a/practice/prep6.py +++ b/practice/prep6.py @@ -300,10 +300,22 @@ class Compare(Expr): ... ('<=', Num(4.5))]) >>> expr.evaluate() False + >>> expr = Compare(Num(1), [ + ... ('<=', Num(4.5)), + ... ('<=', Num(2)), + ... ('<', Num(4.5))]) + >>> expr.evaluate() + False """ left = self.left.evaluate() - return all((left < c[1].evaluate() if c[0] == '<' else left <= c[1].evaluate()) - for c in self.comparisons) + for c in self.comparisons: + v = c[1].evaluate() + if c[0] == '<' and left >= v: + return False + if c[0] == '<=' and left > v: + return False + left = v + return True def __str__(self) -> str: """Return a string representation of this comparison expression.