""" Multistate Sales Tax Calculator """

import os
from decimal import Decimal
from decimal import InvalidOperation

def prompt_decimal(prompt):
    """ Using the prompt, attempt to get a decimal from the user """
    while True:
        try:
            return Decimal(input(prompt))
        except InvalidOperation:
            print('Enter a valid number')

def dollar(amount):
    """ Given an amount as a number
    Return a string formatted as a dollar amount
    """
    amount = round(amount, 2)
    return '${0:0.2f}'.format(amount)

STATE_RATES = {
    'ILLINOIS': Decimal('0.08'),
    'IL': Decimal('0.08'),
    'WISCONSIN': Decimal('0.05'),
    'WI': Decimal('0.05'),
}

WISCONSIN_RATES = {
    'EAU CLAIRE': Decimal('0.005'),
    'DUNN': Decimal('0.004')
}

def ex20():
    """ Prompt for the order amount and state
    If the state is Wisconsin, prompt for the county
    Print the sales tax and total amount
    """

    amount = prompt_decimal('What is the order amount? ')
    state = input('What state do you live in? ')
    if state.upper() in STATE_RATES:
        rate = STATE_RATES[state.upper()]
    else:
        rate = Decimal(0)

    if state.upper() == 'WISCONSIN':
        county = input('What county do you live in? ')
        if county.upper() in WISCONSIN_RATES:
            rate += WISCONSIN_RATES[county.upper()]

    tax = amount * rate
    total = tax + amount

    output = os.linesep.join([
        'The tax is {}'.format(dollar(tax)),
        'The total is {}'.format(dollar(total))])
    print(output)

if __name__ == '__main__':
    ex20()

[((23, 16, 23, 31), 'decimal.Decimal', 'Decimal', ({(23, 24, 23, 30): '"""0.08"""'}, {}), "('0.08')", False, 'from decimal import Decimal\n'), ((24, 10, 24, 25), 'decimal.Decimal', 'Decimal', ({(24, 18, 24, 24): '"""0.08"""'}, {}), "('0.08')", False, 'from decimal import Decimal\n'), ((25, 17, 25, 32), 'decimal.Decimal', 'Decimal', ({(25, 25, 25, 31): '"""0.05"""'}, {}), "('0.05')", False, 'from decimal import Decimal\n'), ((26, 10, 26, 25), 'decimal.Decimal', 'Decimal', ({(26, 18, 26, 24): '"""0.05"""'}, {}), "('0.05')", False, 'from decimal import Decimal\n'), ((30, 18, 30, 34), 'decimal.Decimal', 'Decimal', ({(30, 26, 30, 33): '"""0.005"""'}, {}), "('0.005')", False, 'from decimal import Decimal\n'), ((31, 12, 31, 28), 'decimal.Decimal', 'Decimal', ({(31, 20, 31, 27): '"""0.004"""'}, {}), "('0.004')", False, 'from decimal import Decimal\n'), ((45, 15, 45, 25), 'decimal.Decimal', 'Decimal', ({(45, 23, 45, 24): '0'}, {}), '(0)', False, 'from decimal import Decimal\n')]