Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# final-project
final-project python code challenge
# final-project
final-project python code challenge
my forked project
Binary file added StateCap-screen/results-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions capital.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import sys
import json
import pytest

STATES_CAPITALS = {
'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',
}


# CAPITALS_STATES = {capital:state for state, capital in STATES_CAPITALS.items()}
def capital_of_Idaho():
return STATES_CAPITALS['Idaho']


def all_states():
return STATES_CAPITALS.keys()


def all_capitals():
return STATES_CAPITALS.values()


def states_capitals_string():
return ' , '.join([f'{state} - > {capital}' for state, capital in STATES_CAPITALS.items()])


def get_state():
sorted_states = sorted(STATES_CAPITALS.items())
return ' , '.join([f'{state} - > {capital}' for (state, capital) in sorted_states])


def get_state_7():
return {capital: state for state, capital in STATES_CAPITALS.items()}


# def get_state_8(capital):
# return CAPITALS_STATES.get(capital, "None")

# new_dict = {}
# for state, capital in STATES_CAPITALS.items():
# new_dict[capital] = state
# def test_state_to_capital():
# assert 'Cheyenne' == STATES_CAPITALS['Wyoming']


print("1)", capital_of_Idaho())
print("2)", all_states())
print("3)", all_capitals())
print("4)", states_capitals_string())
print("5)", get_state())
print("7)", get_state_7())
# a= get_state_8('Lansing')
# print (a)


## with pytest.raises(KeyError):
# STATES_CAPITALS['']


# 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__)


# if __name__ == '__main__':
# sys.exit(main())
Binary file added string-screen/string-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 71 additions & 47 deletions strings.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,71 @@
"""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


def reversed_words(a_string):
pass


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()

"""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 chunk

import pytest


def no_duplicates(a_string):
return list(dict.fromkeys(a_string))
mylist = no_duplicates ("monty""pythons""flying""circus")
print("1)",mylist)


def reversed_words(a_string):
words = a_string.split(' ')
reverse_a_string = ' '.join(reversed(words))
return reverse_a_string


if __name__ == "__main__":
list = 'monty pythons flying circus'
print("2)",reversed_words(list))


def four_char_strings(a_string, chunk):
lst = []
if chunk <= len(a_string):
lst.extend([a_string[:chunk]])
lst.extend(four_char_strings(a_string[chunk:], chunk,))
return lst


a_string = "monty pythons flying circus"
print("3)",four_char_strings(a_string, 4))

#



#
#
# 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()