From e6cd69e545c70689ce4494b5b4302761df9741bf Mon Sep 17 00:00:00 2001 From: Shardul Silswal Date: Tue, 2 Oct 2018 14:26:50 +0530 Subject: [PATCH 1/2] Handle invalid operation --- hand-calculator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hand-calculator.py b/hand-calculator.py index 1d520c0e..cedba853 100644 --- a/hand-calculator.py +++ b/hand-calculator.py @@ -76,7 +76,7 @@ def start_calculator(): calc_text = "" info = "Enter first number" count_clear_frames = 0 - cam = cv2.VideoCapture(1) + cam = cv2.VideoCapture(0) while True: _, img = cam.read() img = cv2.flip(img, 1) @@ -130,7 +130,10 @@ def start_calculator(): info = "Clear screen" second = '' flag['clear'] = True - calc_text += "= "+str(eval(calc_text)) + try: + calc_text += "= "+str(eval(calc_text)) + except: + calc_text = "Invalid operation" elif first != '': flag['first'] = True info = "Enter operator" From 8d9f2e37854d7843743da1c00b235b6cd9767696 Mon Sep 17 00:00:00 2001 From: Shardul Silswal Date: Tue, 2 Oct 2018 14:28:30 +0530 Subject: [PATCH 2/2] changed camera index --- hand-calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hand-calculator.py b/hand-calculator.py index cedba853..86e4fff8 100644 --- a/hand-calculator.py +++ b/hand-calculator.py @@ -76,7 +76,7 @@ def start_calculator(): calc_text = "" info = "Enter first number" count_clear_frames = 0 - cam = cv2.VideoCapture(0) + cam = cv2.VideoCapture(1) while True: _, img = cam.read() img = cv2.flip(img, 1)