From 5e000b949637d84e3304595a08fbea30c4378801 Mon Sep 17 00:00:00 2001 From: Anant Kaushik Date: Sun, 13 Oct 2019 20:18:11 +0530 Subject: [PATCH] Challenge 1 --- .../anantkaushik/challenge1.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Challenge questions/anantkaushik/challenge1.py diff --git a/Challenge questions/anantkaushik/challenge1.py b/Challenge questions/anantkaushik/challenge1.py new file mode 100644 index 0000000..f00b027 --- /dev/null +++ b/Challenge questions/anantkaushik/challenge1.py @@ -0,0 +1,25 @@ +def encodeString(sentence): + sentence = sentence.split() + for i in range(len(sentence)): + sentence[i] = sentence[i].capitalize() + return "".join(sentence) + +def decodeString(sentence): + if not sentence: + return "" + decodedSentence = [] + word = sentence[0] + for i in range(1,len(sentence)): + if sentence[i].isupper(): + decodedSentence.append(word) + word = sentence[i].lower() + else: + word += sentence[i] + decodedSentence.append(word) + return " ".join(decodedSentence) + +sentence = input("Enter a String: ") +encodedSentence = encodeString(sentence) +decodedSentence = decodeString(encodedSentence) +print("Converted String is {}".format(encodedSentence)) +print("Original String is {}".format(decodedSentence)) \ No newline at end of file