I need some help with my math homework. I have a number of problems I need to return the derivative for.

They will all be of the form:  
ax^b,  
A and B are both integers, but can be positive or negative.
Note: 
  - if b is 1, then the equation will be ax.  
  - if b is 0, then the equation will be 0.  
  
Examples:
  3x^3   -> 9x^2  
  3x^2   -> 6x  
  3x     -> 3  
  3      -> 0  
  3x^-1  -> -3x^-2  
  -3x^-2 -> 6x^-3  

If you don't remember how derivatives work, here's a link with some basic rules: https://www.mathsisfun.com/calculus/derivatives-rules.html

Difficulty: introductory

Starter code:

def get_derivative(s):
	

Solutions:
def get_derivative(s):
    if '^' in s:
        f,t = map(int, s.split('x^'))
        return '{}x'.format(f*t) if t==2 else '{}x^{}'.format(f*t, t-1)
    elif 'x' in s: return s[:-1]
    else: return '0'

def get_derivative(s):
    if 'x' not in s: return '0'
    if '^' not in s: return s.replace('x', '')
    a, b = [int(n) for n in s.split('x^')]
    a *= b
    b -= 1
    if b == 1: return '{}x'.format(a)
    return '{}x^{}'.format(a, b)

def get_derivative(s):
    if 'x' not in s:
        return '0'
    a = int(s.split('x')[0])
    b = 1
    parts = s.split('^')
    if len(parts) > 1:
        b = int(parts[1])
    if b == 2:
        return str(a * b) + 'x'
    elif b == 1:
        return str(a * b)
    return str(a * b) + 'x^' + str(b-1) 

def get_derivative(s):
    if "x" not in s:
        return "0"
    elif s[-1] == "x":
        return s[:-1]
    else:
        b, e = [int(p) for p in s.split("x^")]
        return f"{b*e}x{'^'+str(e-1) if e != 2 else ''}"

def get_derivative(string):
    if not 'x' in string:
        return '0'
    if not '^' in string:
        return string[:-1]
    coef, exp = list(map(int, string.split('x^')))
    return f"{coef * exp}x^{exp - 1}" if exp != 2 else f"{coef * exp}x"


def get_derivative(f):
    a, b = map(int, (f + '^%d' % ('x' in f)).replace('x', '').split('^')[:2])
    return {0: '0', 1: '%d' % a, 2: '%dx' % (a*b)}.get(b, '%dx^%d' % (a*b, b-1))

import re

def get_derivative(s):
    a,b = map(int, re.sub(r'^(\d+)$', r'\1x^0', re.sub(r'x$', 'x^1', s)).split("x^"))
    return re.sub(r'\^1$|x\^0', '', "{}x^{}".format(a*b, b-1*bool(b)))

def get_derivative(string):
    if string.endswith('x'):
        return string[:-1]
    if 'x^' not in string:
        return '0'
    a, b = string.split('x^')
    return 'x^'.join([str(int(a)*int(b)), str(int(b)-1)]) if b != '2' else str(int(a)*2)+'x'

def get_derivative(str):
    if 'x' not in str: return '0'
    if '^' not in str: return str[:-1]
    a,b = str.split('^')
    na = int(a[:-1]) * int(b)
    b = int(b)-1
    if b == 1: 
        return '{}x'.format(na)
    else:
        return '{}x^{}'.format(na,b)


def get_derivative(string):
    if string.endswith('x'):
        return string.split('x')[0]
    elif len(string) == 1:
        return '0'
    else:
        s = list(map(int, string.split("x^")))
        second = s[1] - 1
        return f"{s[0] * s[1]}x{'^' + str(second) if second != 1 else ''}"