From 34b98852bf580dead8c2e7d4b71163b3d62e62cb Mon Sep 17 00:00:00 2001 From: Manuel Rapp Date: Tue, 17 Jul 2018 09:25:44 +0200 Subject: [PATCH 1/3] This is much better. Not. What? Dab on the haters :kappa: --- my_first_calculator.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/my_first_calculator.py b/my_first_calculator.py index bf7c560..3f37ce1 100644 --- a/my_first_calculator.py +++ b/my_first_calculator.py @@ -1,14 +1,36 @@ # my_first_calculator.py by AceLewis # TODO: Make it work for all floating point numbers too -if 3/2 == 1: # Because Python 2 does not know maths +if 3 / 2 == 1: # Because Python 2 does not know maths input = raw_input # Python 2 compatibility + +def dont_crash(msg, sign=False): + if sign: + while True: + try: + good_name = input(msg) # can't give an error. dab on the haiters + if good_name in ("+", "-", "/", "*"): + return good_name + else: + print("{0} not supported".fomrat(good_name)) + except KeyboardInterrupt: + print("\nNo escape now!") # But still have to catch this one + else: + while True: + try: + return int(input(msg)) + except KeyboardInterrupt: + print("\nNo escape now!") + except ValueError: + print("Are you smart enough to enter a number?! (I'm not)") + print('Welcome to this calculator!') print('It can add, subtract, multiply and divide whole numbers from 0 to 50') -num1 = int(input('Please choose your first number: ')) -sign = input('What do you want to do? +, -, /, or *: ') -num2 = int(input('Please choose your second number: ')) +num1 = dont_crash('Please choose your first number: ') +sign = dont_crash('What do you want to do? +, -, /, or *: ', True) +num2 = dont_crash('Please choose your second number: ') + if num1 == 0 and sign == '+' and num2 == 0: print("0+0 = 0") From 9296916004e45f20c91c91df31bb8a63e54ea85d Mon Sep 17 00:00:00 2001 From: Manuelraa Date: Sun, 10 Nov 2019 14:31:07 +0100 Subject: [PATCH 2/3] Fix stupid typo Co-Authored-By: numbermaniac <5206120+numbermaniac@users.noreply.github.com> --- my_first_calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_first_calculator.py b/my_first_calculator.py index 3f37ce1..ae8a1aa 100644 --- a/my_first_calculator.py +++ b/my_first_calculator.py @@ -9,7 +9,7 @@ def dont_crash(msg, sign=False): if sign: while True: try: - good_name = input(msg) # can't give an error. dab on the haiters + good_name = input(msg) # can't give an error. dab on the haters if good_name in ("+", "-", "/", "*"): return good_name else: From bf64421cfc22a3bc24e1f3fbdd82fecdb7fcad40 Mon Sep 17 00:00:00 2001 From: Manuelraa Date: Sun, 10 Nov 2019 14:31:50 +0100 Subject: [PATCH 3/3] This pull request was supposet to have a bug. But someone doesn't agree Co-Authored-By: Caelean Barnes <5150563+caelean@users.noreply.github.com> --- my_first_calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_first_calculator.py b/my_first_calculator.py index ae8a1aa..47d4a89 100644 --- a/my_first_calculator.py +++ b/my_first_calculator.py @@ -13,7 +13,7 @@ def dont_crash(msg, sign=False): if good_name in ("+", "-", "/", "*"): return good_name else: - print("{0} not supported".fomrat(good_name)) + print("{0} not supported".format(good_name)) except KeyboardInterrupt: print("\nNo escape now!") # But still have to catch this one else: