From c645988ef31b1addd32c3e7f571d9fc82d371b91 Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 21 Mar 2017 18:24:46 +0100 Subject: [PATCH] Enhanced handling of integers by light_switch() --- c4ctrl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/c4ctrl.py b/c4ctrl.py index 6c7fb36..daabd19 100755 --- a/c4ctrl.py +++ b/c4ctrl.py @@ -210,7 +210,8 @@ class C4Room: userinput = self._interactive_light_switch() if len(userinput) != len(self.switches): - if int(userinput) <= 15: + if int(userinput) <= 15 and len(bin(int(userinput))) <= len(self.switches)+2: + # +2 because bin() returns something like 'b0...' # Try to interpret as integer binary = bin(int(userinput))[2:] userinput = str(len(self.switches)*'0')[:-len(binary)] + binary