Created
June 3, 2021 13:11
-
-
Save terminaldweller/222b1dde59faf616384730c65469dde0 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# _*_ coding=utf-8 _*_ | |
import argparse | |
import code | |
import signal | |
import sys | |
import math | |
def SigHandler_SIGINT(signum, frame): | |
print() | |
sys.exit(0) | |
class Argparser(object): | |
def __init__(self): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--string", type=str, help="string") | |
parser.add_argument("--bool", action="store_true", | |
help="bool", default=False) | |
parser.add_argument("--dbg", action="store_true", | |
help="debug", default=False) | |
self.args = parser.parse_args() | |
# write code here | |
def premain(argparser): | |
signal.signal(signal.SIGINT, SigHandler_SIGINT) | |
# here | |
a = input("please enter a:") | |
b = input("please enter b:") | |
c = input("please enter c:") | |
a = int(a) | |
b = int(b) | |
c = int(c) | |
if a == 0: | |
print("not a second degree polynominal") | |
sys.exit(1) | |
if b*b > 4*a*c: | |
root1 = (-b-math.sqrt(b*b-4*a*c))/2/a | |
root2 = (-b+math.sqrt(b*b-4*a*c))/2/a | |
print("root1: ", root1, " root2: ", root2) | |
else: | |
print("roots will have imaginary parts") | |
def main(): | |
argparser = Argparser() | |
if argparser.args.dbg: | |
try: | |
premain(argparser) | |
except Exception as e: | |
if hasattr(e, "__doc__"): | |
print(e.__doc__) | |
if hasattr(e, "message"): | |
print(e.message) | |
variables = globals().copy() | |
variables.update(locals()) | |
shell = code.InteractiveConsole(variables) | |
shell.interact(banner="DEBUG REPL") | |
else: | |
premain(argparser) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment