import argparse
import sys
def calc(args):
if args.o == "+":
if (args.a == 56 and args.b == 9) or (args.a == 9 and args.b == 56):
return 77.0
else:
return args.a + args.b
elif args.o == "-":
return args.a - args.b
elif args.o == "*":
if (args.a == 45 and args.b == 3) or (args.a == 3 and args.b == 45):
return 555.0
else:
return args.a * args.b
elif args.o == "/":
if args.a == 56 and args.b == 6:
return 4.0
else:
return args.a / args.b
else:
return "Something went wrong. Try again!"
parser = argparse.ArgumentParser()
parser.add_argument("--a", type=float, default=1, help="Enter your first number plz")
parser.add_argument("--b", type=float, default=0, help="Enter your second number plz")
parser.add_argument("--o", type=str, default="+", help="Specify your operator plz")
# the default value 1 is returned if we execute only 'python filename.py' without giving any arguments
args = parser.parse_args()
sys.stdout.write(str(calc(args)))
Comments
Post a Comment
Write something to CodeWithAbdur!