Skip to content

Commit 7c818bb

Browse files
Merge pull request #25 from anantkaushik/master
Added Challenge 1 from Challenge Questions
2 parents 6de8fb3 + 5e000b9 commit 7c818bb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def encodeString(sentence):
2+
sentence = sentence.split()
3+
for i in range(len(sentence)):
4+
sentence[i] = sentence[i].capitalize()
5+
return "".join(sentence)
6+
7+
def decodeString(sentence):
8+
if not sentence:
9+
return ""
10+
decodedSentence = []
11+
word = sentence[0]
12+
for i in range(1,len(sentence)):
13+
if sentence[i].isupper():
14+
decodedSentence.append(word)
15+
word = sentence[i].lower()
16+
else:
17+
word += sentence[i]
18+
decodedSentence.append(word)
19+
return " ".join(decodedSentence)
20+
21+
sentence = input("Enter a String: ")
22+
encodedSentence = encodeString(sentence)
23+
decodedSentence = decodeString(encodedSentence)
24+
print("Converted String is {}".format(encodedSentence))
25+
print("Original String is {}".format(decodedSentence))

0 commit comments

Comments
 (0)