diff --git a/StateCap.py b/StateCap.py index 73fcf7f..fcb627f 100644 --- a/StateCap.py +++ b/StateCap.py @@ -70,32 +70,29 @@ def capital_of_Idaho(): - # Your code here - pass + return STATES_CAPITALS['Idaho'] def all_states(): - # Your code here - pass + return list(STATES_CAPITALS.keys()) def all_capitals(): - # Your code here - pass + return list(STATES_CAPITALS.values()) def states_capitals_string(): - # Your code here - pass - - + return ', '.join(f'{state} -> {capital}' for state, capital in sorted(STATES_CAPITALS.items())) def get_state(capital): - pass - + states = [state for state, cap in STATES_CAPITALS.items() if cap == capital] + if not states: + raise KeyError("No state found for the given capital.") + if len(states) > 1: + raise ValueError("Multiple states have the same capital.") + return states[0] def test_state_to_capital(): assert 'Cheyenne' == STATES_CAPITALS['Wyoming'] - def test_state_to_capital_unknown(): with pytest.raises(KeyError): STATES_CAPITALS[''] @@ -104,14 +101,15 @@ def test_state_to_capital_unknown(): def test_capital_to_state(): assert 'Wyoming' == get_state('Cheyenne') - def test_capital_to_state_unknown(): with pytest.raises(KeyError): get_state('') - +#def main(): +# return pytest.main(__file__) + def main(): - return pytest.main(__file__) + return pytest.main([__file__]) if __name__ == '__main__': diff --git a/__pycache__/StateCap.cpython-310-pytest-6.2.5.pyc b/__pycache__/StateCap.cpython-310-pytest-6.2.5.pyc new file mode 100644 index 0000000..cc42cca Binary files /dev/null and b/__pycache__/StateCap.cpython-310-pytest-6.2.5.pyc differ diff --git a/__pycache__/strings.cpython-310-pytest-6.2.5.pyc b/__pycache__/strings.cpython-310-pytest-6.2.5.pyc new file mode 100644 index 0000000..ffae37e Binary files /dev/null and b/__pycache__/strings.cpython-310-pytest-6.2.5.pyc differ diff --git a/strings.py b/strings.py index 7915338..88fd9c5 100644 --- a/strings.py +++ b/strings.py @@ -1,26 +1,15 @@ -"""With this string: -'monty pythons flying circus' -Create a function that returns a sorted string with no duplicate characters -(keep any whitespace): -Example: ' cfghilmnoprstuy' -Create a function that returns the words in reverse order: -Example: ['circus', 'flying', 'pythons', 'monty'] -Create a function that returns a list of 4 character strings: -Example: ['mont', 'y py', 'thon', 's fl', 'ying', ' cir', 'cus'] -### git comment -""" import pytest def no_duplicates(a_string): - pass + return ''.join(sorted(set(a_string))) def reversed_words(a_string): - pass + return a_string.split()[::-1] def four_char_strings(a_string): - pass + return [a_string[i:i+4] for i in range(0, len(a_string), 4)] def test_no_duplicates(): @@ -39,9 +28,9 @@ def test_four_char_strings(): def main(): - return pytest.main(__file__) + return pytest.main([__file__]) if __name__ == '__main__': main() - +