-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapsTwoPosInaStr.py
More file actions
19 lines (17 loc) · 939 Bytes
/
capsTwoPosInaStr.py
File metadata and controls
19 lines (17 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#Write a function that capitalizes the given positions in a string
def capitalizeTwoLetters(pos1, pos2, inStr):
lenStr = len(inStr)
if lenStr < 1 or pos1 < 0 or pos1 >= lenStr or pos2 < 0 or pos2 >= lenStr or pos1 > pos2:
return "error in inputs pos1 - {} pos2 - {} str - {}".format(pos1, pos2, inStr)
else:
if pos1 == pos2:
#concatenate portion before pos1 and portion from pos1 with pos1 capitalized
res = inStr[:pos1] + inStr[pos1:].capitalize()
else:
#concatenate portion before pos1, portion from pos1 until pos2 with pos1 capitalized,
#portion from pos2 all the way to the end with pos2 capitalized
res = inStr[:pos1] + inStr[pos1: pos2].capitalize() + inStr[pos2:].capitalize()
return res
capitalizeTwoLetters(0, 6, "wonderland")
#capitalizeTwoLetters(0, 0, "wonderland")
#capitalizeTwoLetters(9, 9, "wonderland")