From d99559133933a38a5239dd49bf3f0502d2cef1b7 Mon Sep 17 00:00:00 2001 From: Sofiia2001 Date: Sun, 13 Oct 2019 14:33:41 +0300 Subject: [PATCH] Adding the solved problem 1 --- Challenge questions/Sofiia2001/problem_1.py | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Challenge questions/Sofiia2001/problem_1.py diff --git a/Challenge questions/Sofiia2001/problem_1.py b/Challenge questions/Sofiia2001/problem_1.py new file mode 100644 index 0000000..4957842 --- /dev/null +++ b/Challenge questions/Sofiia2001/problem_1.py @@ -0,0 +1,33 @@ +def formatting(sentence): + sentence = list(sentence) + for symbol in range(len(sentence) - 1): + if sentence[symbol] == ' ': + sentence[symbol] = '' + sentence[symbol + 1] = sentence[symbol + 1].upper() + + sentence = ''.join(sentence) + return sentence + + +def formatting_back(sentence): + to_return = [sentence[0]] + for symbol in sentence[1:]: + if symbol == symbol.upper(): + to_return.append(' ') + to_return.append(symbol.lower()) + else: + to_return.append(symbol) + to_return = ''.join(to_return) + return to_return + + +def main(): + sentence = str(input('Enter yor string: ')) + formatted = formatting(sentence) + print(f'Formatted: {formatted}') + formatted_back = formatting_back(formatted) + print(f'Formatted back: {formatted_back}') + + +if __name__ == '__main__': + main() \ No newline at end of file