Last active
March 13, 2020 13:48
-
-
Save jakariyaa/a1214a25188e5625f9767a904d949cd3 to your computer and use it in GitHub Desktop.
Hello there! It's an updated version of the Simple PYTHON Calculator made with Python 3 by me. This project is Open Source so you can modify or use this PYTHON Calculator without any kind of permission. Thank You! <3 <3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple Calculator made with Python. | |
# This Calculator is Developed by Zakariya Abbas. | |
# This project is open source so anyone can modify and use it without any permission. | |
print("Simple PYTHON Calculator \n" | |
"Version : 3.0.0 Build 10 \n" | |
"~~-~~~~~~<<<>>>~~~~~~-~~") | |
def calc_func(first_value, second_value, mmath_type): | |
if mmath_type == 1: | |
return first_value + second_value | |
elif mmath_type == 2: | |
return first_value - second_value | |
elif mmath_type == 3: | |
return first_value * second_value | |
elif mmath_type == 4: | |
try: | |
return first_value / second_value | |
except ZeroDivisionError: | |
print("Couldn't divide the first value with Zero.") | |
elif mmath_type > 4 or mmath_type < 1: | |
return "Error:0x07 'Choose the type of math carefully!'" | |
else: | |
return "Calculator faced unexpected ERROR. \n Will improve it more in the near future." | |
calc_run = False | |
while True: | |
print("Please type 'help' to see a list of commands.") | |
cmd = input("> ") | |
if cmd.lower() == 'help': | |
print("Commands -- Actions \n" | |
"help -- Shows a list of commands\n" | |
"start -- Starts the calculator\n" | |
"stop -- Stops the calculator\n" | |
"exit -- Exit the machine\n") | |
continue | |
elif cmd.lower() == 'start': | |
calc_run = True | |
print("Calculator Started \n" | |
" /--o--\ ") | |
while calc_run: | |
print("Input the first value below.....") | |
first_value = input("> ") | |
print("Input the second value below.....") | |
second_value = input("> ") | |
print(" \n " | |
"------------------" | |
" \n ") | |
print("Choose the type of math : Please type the number only.") | |
print("1: Addition (plus or +) \n" | |
"2: Subtraction (minus or -) \n" | |
"3: Multiplication (× or *) \n" | |
"4: Division (÷ or /) \n") | |
mmath_type = input("> ") | |
try: | |
result = calc_func(float(first_value), float(second_value), int(mmath_type)) | |
print(f"Result : {result}") | |
except ValueError: | |
print("Result : Error:0x09 'Please try again with correct value!'") | |
continue | |
print("─────────────────────────────────\n" | |
"Type 'stop' to stop the Calculator\n" | |
"─────────────────────────────────") | |
cmd2 = input("> ") | |
if cmd2.lower() == 'stop': | |
calc_run = False | |
elif cmd2.lower() !='stop': | |
print("Calculator Restarted") | |
continue | |
else: | |
print("Calculator Stopped") | |
elif cmd.lower() == 'stop' and not calc_run: | |
print("Calculator already stopped. Start it first before stopping.") | |
elif cmd.lower() == 'exit': | |
print("Successfully exited the machine.") | |
print(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n" | |
"Thank You for using my PYTHON Calculator! \n" | |
"This Calculator is Developed by Zakariya Abbas.") | |
break | |
# Visit "http://bit.ly/SPCupdates" for latest updates. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment