Posts

Showing posts with the label command line utility

Command Line Utility of a Faulty Calculator

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, defaul