-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_mutations.py
35 lines (28 loc) · 979 Bytes
/
string_mutations.py
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
34
35
# Task
# Read a given string, change the character at a given index and then print the modified string.
# Function Description
# Complete the mutate_string function in the editor below.
# mutate_string has the following parameters:
# string string: the string to change
# int position: the index to insert the character at
# string character: the character to insert
# Returns
# string: the altered string
def mutate_string(string, position, character):
l = list(string)
l[position] = character
return ''.join(l)
if __name__ == '__main__':
s = input()
i, c = input().split()
s_new = mutate_string(s, int(i), c)
print(s_new)
#-------------------------OR------------------------
def mutate_string(string, position, character):
new_string = string[:position] + character + string[position + 1:]
return new_string
if __name__ == '__main__':
s = input()
i, c = input().split()
s_new = mutate_string(s, int(i), c)
print(s_new)