From 666fa023ed2dedb8ea1ab201a8f10803f142175a Mon Sep 17 00:00:00 2001 From: YuvalSal99 Date: Sat, 13 May 2023 11:17:07 +0000 Subject: [PATCH 1/5] first try --- StateCap.py | 79 +++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/StateCap.py b/StateCap.py index 73fcf7f..2974a9f 100644 --- a/StateCap.py +++ b/StateCap.py @@ -68,51 +68,60 @@ 'Wyoming' : 'Cheyenne', } - def capital_of_Idaho(): - # Your code here + capital = 'Boise' + for i in STATES_CAPITALS: + if STATES_CAPITALS[i] == capital: + print(STATES_CAPITALS[i]) pass def all_states(): - # Your code here + state = list(STATES_CAPITALS.keys()) + print('states =', state) pass def all_capitals(): - # Your code here + capitals = list(STATES_CAPITALS.values()) + print('capitals =' ,capitals) pass + def states_capitals_string(): # Your code here pass - - -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 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()) +# +# +# 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 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()) + +capital_of_Idaho() +all_states() +all_capitals() From 515fc21c030512d238c30b01f623b013fcb50e16 Mon Sep 17 00:00:00 2001 From: YuvalSal99 Date: Sat, 13 May 2023 16:03:46 +0000 Subject: [PATCH 2/5] python final --- StateCap.py | 80 +++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/StateCap.py b/StateCap.py index 2974a9f..cdc81ab 100644 --- a/StateCap.py +++ b/StateCap.py @@ -68,60 +68,62 @@ 'Wyoming' : 'Cheyenne', } + def capital_of_Idaho(): capital = 'Boise' for i in STATES_CAPITALS: if STATES_CAPITALS[i] == capital: - print(STATES_CAPITALS[i]) + print('Q1:', STATES_CAPITALS[i]) pass def all_states(): state = list(STATES_CAPITALS.keys()) - print('states =', state) + print('Q2:', state) pass def all_capitals(): capitals = list(STATES_CAPITALS.values()) - print('capitals =' ,capitals) + print('Q3:', capitals) pass def states_capitals_string(): - # Your code here + list = [] + for state, capital in STATES_CAPITALS.items(): + list.append(state) + list.append('->') + list.append(capital) + list.append(',') + string = ' '.join(list) + print('Q4:', string) pass -# -# -# 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 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()) - -capital_of_Idaho() -all_states() -all_capitals() + + +def get_state(capital): + capital_input = capital + state_input = '' + flag = 0 + for state, capital in STATES_CAPITALS.items(): + if capital == capital_input: + state_input += state + ' ' + flag = 1 + if flag == 0: + state_input = 'State not exist' + return state_input + + + + +def main(): + capital = input("Write a capital and we will tell you the state:") + print("the state is: ", get_state(capital)) + + capital_of_Idaho() + all_states() + all_capitals() + states_capitals_string() + + +if __name__ == '__main__': + sys.exit(main()) From 7473fb7672a23f5f5165fa209e302fe98c456e72 Mon Sep 17 00:00:00 2001 From: YuvalSal99 Date: Fri, 19 May 2023 12:14:25 +0000 Subject: [PATCH 3/5] strings project --- strings.py | 63 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/strings.py b/strings.py index 7915338..97bf5ff 100644 --- a/strings.py +++ b/strings.py @@ -9,39 +9,64 @@ Example: ['mont', 'y py', 'thon', 's fl', 'ying', ' cir', 'cus'] ### git comment """ -import pytest +"""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 +""" + + +string='monty pythons flying circus' def no_duplicates(a_string): + sort='' + for i in a_string: + if i != ' ': + if i not in sort: + sort = sort + i + yep = sorted(sort) + string=''.join(yep) + print(string) pass def reversed_words(a_string): - pass + spl = a_string.split() + reverse = spl[::-1] + print(reverse) + 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'] + j = 0 + temp = '' + new_string = [] + print('Start:' + a_string) + for i in a_string: + temp = temp + i + if j == 3 : + new_string.append(temp) + temp = '' + j = 0 + else: + j = j + 1 + new_string.append(temp) + print(new_string) + pass -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__) - + no_duplicates(string) + reversed_words(string) + four_char_strings(string) if __name__ == '__main__': main() - From 658b53d4e0cd8eea7cb63b92db9b83cd804f0f2e Mon Sep 17 00:00:00 2001 From: YuvalSal99 Date: Wed, 31 May 2023 19:28:59 +0000 Subject: [PATCH 4/5] last commit --- strings.py | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/strings.py b/strings.py index 97bf5ff..1400668 100644 --- a/strings.py +++ b/strings.py @@ -1,14 +1,4 @@ -"""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 -""" + """With this string: 'monty pythons flying circus' Create a function that returns a sorted string with no duplicate characters @@ -21,6 +11,7 @@ ### git comment """ +import pytest string='monty pythons flying circus' @@ -32,14 +23,14 @@ def no_duplicates(a_string): sort = sort + i yep = sorted(sort) string=''.join(yep) - print(string) + return string pass def reversed_words(a_string): spl = a_string.split() reverse = spl[::-1] - print(reverse) + return reverse pass @@ -50,23 +41,39 @@ def four_char_strings(a_string): print('Start:' + a_string) for i in a_string: temp = temp + i - if j == 3 : + if j == 3: new_string.append(temp) temp = '' j = 0 else: j = j + 1 new_string.append(temp) - print(new_string) + return new_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(): - no_duplicates(string) - reversed_words(string) - four_char_strings(string) + + return pytest.main(["strings.py"]) if __name__ == '__main__': main() + + + From 50725a1c0380a800317d10630f2fb6a80fd81edb Mon Sep 17 00:00:00 2001 From: YuvalSal99 Date: Wed, 31 May 2023 19:29:07 +0000 Subject: [PATCH 5/5] last commit --- StateCap.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/StateCap.py b/StateCap.py index cdc81ab..1edcc9d 100644 --- a/StateCap.py +++ b/StateCap.py @@ -109,21 +109,30 @@ def get_state(capital): state_input += state + ' ' flag = 1 if flag == 0: - state_input = 'State not exist' + raise KeyError("value exist") return state_input +def test_state_to_capital(): + assert 'Cheyenne' == STATES_CAPITALS['Wyoming'] +def test_state_to_capital_unknown(): + with pytest.raises(KeyError): + STATES_CAPITALS[''] + + +def test_capital_to_state(): + assert 'Wyoming' == get_state('Cheyenne').strip() -def main(): - capital = input("Write a capital and we will tell you the state:") - print("the state is: ", get_state(capital)) - capital_of_Idaho() - all_states() - all_capitals() - states_capitals_string() +def test_capital_to_state_unknown(): + with pytest.raises(KeyError): + get_state('') + +def main(): + return pytest.main(["StateCap.py"]) + if __name__ == '__main__': sys.exit(main())