-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathproblem_1.py
More file actions
33 lines (26 loc) · 876 Bytes
/
problem_1.py
File metadata and controls
33 lines (26 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()