Skip to content

Instantly share code, notes, and snippets.

@granda
Created January 23, 2017 05:55
Show Gist options
  • Save granda/5438b2fd089cf5e0034cead2a8b9db6c to your computer and use it in GitHub Desktop.
Save granda/5438b2fd089cf5e0034cead2a8b9db6c to your computer and use it in GitHub Desktop.
Outputs sales tax for any five random U.S. states.
# -*- coding: utf-8 -*-
"""
A1 Spec
~~~~~~~
Outputs sales tax for any five random U.S. states.
Example Output:
>> Sales Tax Rates
>> ---------------
>> California: 7.25%
>> Florida: 6.0%
>> Colorado: 2.9%
>> New York: 4.0%
>> Texas: 6.25%
Author: Matthew Granda
Date: January 23, 2017
License: MIT
"""
import random
STATE_SALES_TAX_RATES = {
'Alabama': 4.0,
'Alaska': 0.0,
'Arizona': 5.6,
'Arkansas': 6.5,
'California': 7.25,
'Colorado': 2.9,
'Connecticut': 6.35,
'Delaware': 0.0,
'Florida': 6.0,
'Georgia': 4.0,
'Hawaii': 4.0,
'Idaho': 6.0,
'Illinois': 6.25,
'Indiana': 7.0,
'Iowa': 6.0,
'Kansas': 6.5,
'Kentucky': 6.0,
'Louisiana': 5.0,
'Maine': 5.5,
'Maryland': 6.0,
'Massachusetts': 6.25,
'Michigan': 6.0,
'Minnesota': 6.875,
'Mississippi': 7.0,
'Missouri': 4.225,
'Montana': 0.0,
'Nebraska': 5.5,
'Nevada': 6.85,
'New Hampshire': 0.0,
'New Jersey': 6.875,
'New Mexico': 5.125,
'New York': 4.0,
'North Carolina': 4.75,
'North Dakota': 5.0,
'Ohio': 5.75,
'Oklahoma': 4.5,
'Oregon': 0.0,
'Pennsylvania': 6.0,
'Rhode Island': 7.0,
'South Carolina': 6.0,
'South Dakota': 4.5,
'Tennessee': 7.0,
'Texas': 6.25,
'Utah': 4.7,
'Vermont': 6.0,
'Virginia': 4.3,
'Washington': 6.5,
'West Virginia': 6.0,
'Wisconsin': 5.0,
'Wyoming': 4.0
}
def main():
states = STATE_SALES_TAX_RATES.keys()
randomized_states = sorted(states, key=lambda x: random.random())
print('Sales Tax Rates')
print('-' * 15)
for state in randomized_states[:5]:
print(f'{state}: {STATE_SALES_TAX_RATES[state]}%')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment