Computer Science, asked by fiercespartan, 1 year ago

Alright, for all your coders out there...

I am currently giving you a problem in python and type the code in the answer section for this problem.

This question is based on string manipulation.

Difficulty level - 1 / 5
______________________________________________________

Let's say we have a string. For example, let's say the string is 'Brainle'. This has to be the first input:

The second line of input contains two characters. (x , y )

This says that the string 'y' will have to go in the xth place of the input string.

First case :

input = 'Brainle'
Input2 = 6, y

Then, the output should be printed as : Brainly.

Remember while solving the problem, TAKE THE INPUT BY YOUR SELF. THE INPUT TAKING SHOULD BE ON YOUR CODE!

______________________

Good luck! :)


samrudhi15: answer @illr
samrudhi15: @ille*

Answers

Answered by rakeshchennupati143
8

PROGRAM

strng = input("Enter a string : ")

pos = int(input("Enter position : "))

given_char = input("Enter character to change : ")

length = len(strng)

arr = [0] * length

i = 0

new_str = ""

if pos < length:

   for char in strng:

       arr[i] = char

       i = i + 1

   arr[pos-1] = given_char

   for some in arr:

       new_str = new_str + some

   print("New modified String is : "+new_str)

else:

   print("given position is exceding the given string length")

OUTPUT

Enter a string : rakesh

Enter position : 4

Enter character to change : q

New modified String is : rakqsh


rakeshchennupati143: 1. took string into array
rakeshchennupati143: 2. changed the character using array
rakeshchennupati143: 3. then changed the modified array into string
rakeshchennupati143: your way i tried already but there will be an error that
rakeshchennupati143: 'str' object does not support item assignment
rakeshchennupati143: i got the error so i tried in my way
fiercespartan: To do that, you will need to list(string) and then change it
rakeshchennupati143: even taking lists is also same algorithm
rakeshchennupati143: string into list change specified number then list into string
rakeshchennupati143: there is a question in my profile waiting for someone like you to answer it, 50+25pts hope you will get the answer ;)
Answered by Anonymous
11

\huge\tt{AnsweR}

Refer the attachment.

Hey, there looking for another similar answer?

look into the attachment.

Attachments:
Similar questions