pyCMD; a simple shell to run math and Python commands I made a command line in Python.
Before I go on and add more commands, is my program made well?
I don't like the huge amount of &quot;if&quot; statements in it. But I don't know a better way to do it. (JSON may be used later this is why I have it included)
Here's the code:
import time
import json
print(&quot;Welcome to pyCMD, user\n&quot;)
time.sleep(0.2)
input(&quot;Press enter to start\n&quot;)
time.sleep(0.2)

def SavetoDisk(data, file):
    with open(file, 'w') as outfile:
        json.dump(data, outfile)

def ReadfromDisk(file):
    with open(file) as json_file:
        data = json.load(json_file)
    return data
print('Starting command line, use &quot;help . .&quot; for help')
running = True
commandList = &quot;add | sub | mult | div | exp | tetrate | python&quot;
while running:
    try: 
        userInput = input(': ')
        tokens = userInput.split()
        command = tokens[0] 
        args = [(token) for token in tokens[1:]]
    except: print(&quot;unknown input error&quot;)
    try:
        arg1, arg2 = args
    except ValueError:
        print('Too many or too little args, 2 args required, if you want to not use an arg, use a &quot;.&quot;')
    
    if command == &quot;add&quot;:
        print(float(arg1) + float(arg2))
    
    if command == &quot;sub&quot;:
        print(float(arg1) - float(arg2))
        
    if command == &quot;mult&quot;:
        print(float(arg1) * float(arg2))        #math commands
        
    if command == &quot;div&quot;:
        print(float(arg1) / float(arg2))
    
    if command == &quot;exp&quot;:
        print(float(arg1) ** float(arg2))
        
    if command == &quot;tetrate&quot;:
        for x in range(int(arg2)):
            arg1 = float(arg1) * float(arg1)
        print(arg1)
        
    if command == &quot;python&quot;:
        exec(open(arg1).read())
        
    if command == &quot;help&quot;:
        if arg1 == '.':
            if arg2 == '.':
                print('To see help about a command, type: &quot;help [command] .&quot; for list of commands type: &quot;help command list&quot;')
        
        if arg1 == 'command':
            if arg2 == 'list':
                print(commandList)
                
        if arg1 == 'add':
            print(&quot;Add: \n Description: Adds 2 numbers \n Syntax: add [num1] [num2]&quot;)
            
        if arg1 == 'sub':
            print(&quot;Sub: \nDescription: Subtracts 2 numbers \n Syntax : sub [num1] [num2]&quot;)
        
        if arg1 == 'mult':
            print(&quot;Mult: \nDescription: Multiplies 2 numbers \n Syntax : mult [num1] [num2]&quot;)
            
        if arg1 == 'div':
            print(&quot;Div: \nDescription: Divides 2 numbers \n Syntax : div [num1] [num2]&quot;)
        
        if arg1 == 'exp':
            print(&quot;Exp: \nDescription: Raises 1 number by another \n Syntax : exp [num1] [num2]&quot;)
            
        if arg1 == 'tetrate':
            print(&quot;Tetrate: \nDescription: Tetration \n Syntax : tetrate [num1] [num2]&quot;)
        
        if arg1 == 'python':
            print(&quot;Python: \nDescription: Runs a python script \n Syntax : python [path/to/program.py] .&quot;)
The first thing I notice with your code is that the code is a very long global script. To resolve this I'd start by moving your code into functions.
The actual calculations could be as simple as say:
def add(arg1, arg2):
    print(float(arg1) + float(arg2))

To then get the help information we could add a docstring.
def add(arg1, arg2):
    &quot;&quot;&quot;
    Add:
     Description: Adds 2 numbers
     Syntax: add [num1] [num2]
    &quot;&quot;&quot;
    print(float(arg1) + float(arg2))

We can get both the docstring and the output of the operation with Python. To get the docstring to be nicely formatted we can use textwrap.dedent.
&gt;&gt;&gt; add(&quot;10&quot;, &quot;5&quot;)
15.0
&gt;&gt;&gt; import textwrap
&gt;&gt;&gt; textwrap.dedent(add.__doc__.strip(&quot;\n&quot;))
Add:
 Description: Adds 2 numbers
 Syntax: add [num1] [num2]


To then reduce the amount of lines of code we can bundle all these functions into a dictionary. And just index the dictionary to get a specific function.
COMMANDS = {
    &quot;add&quot;: add,
    &quot;sub&quot;: sub,
    # ...
}

fn = COMMANDS[&quot;add&quot;]
fn(&quot;10&quot;, &quot;5&quot;)

15.0

Whilst you can build the dictionary and execute the commands yourself, you could instead subclass cmd.Cmd. You will need to change the functions slightly to only take a string as input, and prefix do_ to any commands available to the commandline.
import cmd


class PyCMD(cmd.Cmd):
    intro = 'Welcome to pyCMD, user\nStarting command line, use &quot;help&quot; for help'
    prompt = &quot;: &quot;

    def do_add(self, arg):
        &quot;&quot;&quot;
        Add:
         Description: Adds 2 numbers
         Syntax: add [num1] [num2]
        &quot;&quot;&quot;
        arg1, arg2 = arg.split()
        print(float(arg1) + float(arg2))

PyCMD().cmdloop()

Welcome to pyCMD, user
Starting command line, use &quot;help&quot; for help
: help

Documented commands (type help &lt;topic&gt;):
========================================
add  help

: help add

        Add:
         Description: Adds 2 numbers
         Syntax: add [num1] [num2]
        
: add 10 5
15.0

The help is clearly a bit on the broken side. To fix this we can change the docstring after the function.
class PyCMD(cmd.Cmd):
    def do_add(self, arg):
        # ...

    do_add.__doc__ = textwrap.dedent(do_add.__doc__.rstrip(&quot; &quot;).strip(&quot;\n&quot;))

This is a bit ugly and doing this for each function would be horrible. So we can create a function to do this.
def clean_doc(fn):
    fn.__doc__ = textwrap.dedent(fn.__doc__.rstrip(&quot; &quot;).strip(&quot;\n&quot;))


class PyCMD(cmd.Cmd):
    def do_add(self, arg):
        # ...

    clean_doc(do_add)

This is still a bit on the ugly side so we can use @ to do this for us. This is called a decorator. This makes sense because we're decorating how __doc__ is seen. Note that we changed clean_doc to return fn.
def clean_doc(fn):
    fn.__doc__ = textwrap.dedent(fn.__doc__.rstrip(&quot; &quot;).strip(&quot;\n&quot;))
    return fn


class PyCMD(cmd.Cmd):
    @clean_doc
    def do_add(self, arg):
        # ...

We can add another function like clean_doc, but this time make it a closure if you want to easily add your validation of two arguments.
import functools


def command(fn):
    @functools.wraps(fn)
    def wrapper(self, arg):
        args = [token for token in arg.split()]
        try:
            arg1, arg2 = args
        except ValueError:
            print('Too many or too little args, 2 args required, if you want to not use an arg, use a &quot;.&quot;')
        else:
            return fn(self, arg1, arg2)
    return wrapper


class PyCMD(cmd.Cmd):
    @command
    @clean_doc
    def do_add(self, arg1, arg2):
        &quot;&quot;&quot;
        Add:
         Description: Adds 2 numbers
         Syntax: add [num1] [num2]
        &quot;&quot;&quot;
        print(float(arg1) + float(arg2))


import cmd
import textwrap
import functools


def command(fn):
    @functools.wraps(fn)
    def wrapper(self, arg):
        try:
            arg1, arg2 = arg.split()
        except ValueError:
            print('Too many or too little args, 2 args required, if you want to not use an arg, use a &quot;.&quot;')
        else:
            return fn(self, arg1, arg2)
    return wrapper


def clean_doc(fn):
    fn.__doc__ = textwrap.dedent(fn.__doc__.rstrip(&quot; &quot;).strip(&quot;\n&quot;))
    return fn


class PyCMD(cmd.Cmd):
    intro = 'Welcome to pyCMD, user\nStarting command line, use &quot;help&quot; for help'
    prompt = &quot;: &quot;

    @command
    @clean_doc
    def do_add(self, arg1, arg2):
        &quot;&quot;&quot;
        Add:
         Description: Adds 2 numbers
         Syntax: add [num1] [num2]
        &quot;&quot;&quot;
        print(float(arg1) + float(arg2))


PyCMD().cmdloop()

Welcome to pyCMD, user
Starting command line, use &quot;help&quot; for help
: help

Documented commands (type help &lt;topic&gt;):
========================================
add  help

: help add
Add:
 Description: Adds 2 numbers
 Syntax: add [num1] [num2]
: add 10 5
15.0

Other commands left for you to implement