Skip to content
183 changes: 95 additions & 88 deletions StateCap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,110 +9,117 @@
Implement the function def get_state(capital): below so it returns the state.
GOTCHAS: What happens if two states have the same capital name, how do you
handle that?

"""
import sys

import pytest

STATES_CAPITALS = {
'Alabama' : 'Montgomery',
'Alaska' : 'Juneau',
'Arizona' : 'Phoenix',
'Alabama': 'Montgomery',
'Alaska': 'Juneau',
'Arizona': 'Phoenix',
'Arkansas': 'Little Rock',
'California' : 'Sacramento',
'Colorado' : 'Denver',
'Connecticut' : 'Hartford',
'Delaware' : 'Dover',
'Florida' : 'Tallahassee',
'Georgia' : 'Atlanta',
'Hawaii' : 'Honolulu',
'Idaho' : 'Boise',
'Illinois' : 'Springfield',
'Indiana' : 'Indianapolis',
'Iowa' : 'Des Moines',
'Kansas' : 'Topeka',
'Kentucky' : 'Frankfort',
'Louisiana' : 'Baton Rouge',
'Maine' : 'Augusta',
'Maryland' : 'Annapolis',
'Massachusetts' : 'Boston',
'Michigan' : 'Lansing',
'Minnesota' : 'Saint Paul',
'Mississippi' : 'Jackson',
'Missouri' : 'Jefferson City',
'Montana' : 'Helena',
'Nebraska' : 'Lincoln',
'Nevada' : 'Carson City',
'New Hampshire' : 'Concord',
'New Jersey' : 'Trenton',
'New Mexico' : 'Santa Fe',
'New York' : 'Albany',
'North Carolina' : 'Raleigh',
'North Dakota' : 'Bismarck',
'Ohio' : 'Columbus',
'Oklahoma' : 'Oklahoma City',
'Oregon' : 'Salem',
'Pennsylvania' : 'Harrisburg',
'Rhode Island' : 'Providence',
'South Carolina' : 'Columbia',
'South Dakota' : 'Pierre',
'Tennessee' : 'Nashville',
'Texas' : 'Austin',
'Utah' : 'Salt Lake City',
'Vermont' : 'Montpelier',
'Virginia' : 'Richmond',
'Washington' : 'Olympia',
'West Virginia' : 'Charleston',
'Wisconsin' : 'Madison',
'Wyoming' : 'Cheyenne',
'California': 'Sacramento',
'Colorado': 'Denver',
'Connecticut': 'Hartford',
'Delaware': 'Dover',
'Florida': 'Tallahassee',
'Georgia': 'Atlanta',
'Hawaii': 'Honolulu',
'Idaho': 'Boise',
'Illinois': 'Springfield',
'Indiana': 'Indianapolis',
'Iowa': 'Des Moines',
'Kansas': 'Topeka',
'Kentucky': 'Frankfort',
'Louisiana': 'Baton Rouge',
'Maine': 'Augusta',
'Maryland': 'Annapolis',
'Massachusetts': 'Boston',
'Michigan': 'Lansing',
'Minnesota': 'Saint Paul',
'Mississippi': 'Jackson',
'Missouri': 'Jefferson City',
'Montana': 'Helena',
'Nebraska': 'Lincoln',
'Nevada': 'Carson City',
'New Hampshire': 'Concord',
'New Jersey': 'Trenton',
'New Mexico': 'Santa Fe',
'New York': 'Albany',
'North Carolina': 'Raleigh',
'North Dakota': 'Bismarck',
'Ohio': 'Columbus',
'Oklahoma': 'Oklahoma City',
'Oregon': 'Salem',
'Pennsylvania': 'Harrisburg',
'Rhode Island': 'Providence',
'South Carolina': 'Columbia',
'South Dakota': 'Pierre',
'Tennessee': 'Nashville',
'Texas': 'Austin',
'Utah': 'Salt Lake City',
'Vermont': 'Montpelier',
'Virginia': 'Richmond',
'Washington': 'Olympia',
'West Virginia': 'Charleston',
'Wisconsin': 'Madison',
'Wyoming': 'Cheyenne',
}


def capital_of_Idaho():
# Your code here
pass

def all_states():
# Your code here
pass

def all_capitals():
# Your code here
pass

def states_capitals_string():
# Your code here
pass
global STATES_CAPITALS
print(STATES_CAPITALS['Idaho'])



def get_state(capital):
pass



def test_state_to_capital():
assert 'Cheyenne' == STATES_CAPITALS['Wyoming']


def test_state_to_capital_unknown():
with pytest.raises(KeyError):
STATES_CAPITALS['']
def all_states():
global STATES_CAPITALS
for state in list(STATES_CAPITALS.keys()):
print(state)


def test_capital_to_state():
assert 'Wyoming' == get_state('Cheyenne')
def all_capitals():
global STATES_CAPITALS
for capital in list(STATES_CAPITALS.keys()):
print(STATES_CAPITALS[capital])


def test_capital_to_state_unknown():
with pytest.raises(KeyError):
get_state('')
def states_capitals_string():
global STATES_CAPITALS
string = ""
for temp in list(STATES_CAPITALS.keys()):
string += temp + " -> " + STATES_CAPITALS[temp] + ","
string = string[:-1]
print(string)
return string


def main():
return pytest.main(__file__)
def alphabetically_sorted(string):
sorted = string.split(",")
sorted.sort()
string_new = ""
for x in sorted:
string_new += x + ","
string_new = string_new[:-1]
print(string_new)


if __name__ == '__main__':
sys.exit(main())
def get_state(capital):
global STATES_CAPITALS
index = list(STATES_CAPITALS.values()).index(capital)
key = list(STATES_CAPITALS.keys())[index]
print(key)


if __name__ == "__main__":
print("1. - ", end="")
capital_of_Idaho()
print("2. - ", end="")
all_states()
print("3. - ", end="")
all_capitals()
print("4. - ", end="")
string1 = states_capitals_string()
print("5. - ", end="")
alphabetically_sorted(string1)
print(f"7. - ", end="")
get_state("Des Moines")
Empty file added asdasd.txt
Empty file.
53 changes: 25 additions & 28 deletions strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,36 @@
Example: ['mont', 'y py', 'thon', 's fl', 'ying', ' cir', 'cus']
### git comment
"""
import pytest
a_string = 'monty pythons flying circus'


def no_duplicates(a_string):
pass
string = ""
lst = sorted(set(a_string))
for i in lst:
string += i
print(string)


def reversed_words(a_string):
pass
lst = a_string.split(" ")
lst.reverse()
print(lst)


def four_char_strings(a_string):
pass


def test_no_duplicates():
s = 'monty pythons flying circus'
assert no_duplicates(s) == ' cfghilmnoprstuy'


def test_reversed_words():
s = 'monty pythons flying circus'
assert reversed_words(s) == ['circus', 'flying', 'pythons', 'monty']


def test_four_char_strings():
s = 'monty pythons flying circus'
assert four_char_strings(s) == ['mont', 'y py', 'thon', 's fl', 'ying', ' cir', 'cus']


def main():
return pytest.main(__file__)


if __name__ == '__main__':
main()

lst = []
while a_string:
chars = a_string[:4:]
lst.append(chars)
a_string = a_string.replace(chars, "")
print(lst)


if __name__ == "__main__":
print("1. - ", end="")
no_duplicates(a_string)
print("2. - ", end="")
reversed_words(a_string)
print("3. - ", end="")
four_char_strings(a_string)