Question 1 100 pts Write a Python program that performs the following tasks: (1)
ID: 3722549 • Letter: Q
Question
Question 1 100 pts Write a Python program that performs the following tasks: (1) create a variable my-string, and assign '12a#43a5#6a9a#32' to it. Print the original my_string. (2) remove all '#'s from my-string using the replace method (replacing them to empty string). Update and print my string (3) Split my_string using the split method, assign the returned list to variable my list. Print my_list. Original string : 12a#43a5#6a9a#32 After replacement: 12a43a56a9a32 my list is ['12', '43', '56', '9', '32' HTML Editor ParagraphExplanation / Answer
Hello There,
PFB python code for the required functionality along with the output of test run
prog.py
---------------------------------
#!/usr/bin/env python
import string
my_string = '12a#43a5#6a9a#32'
print("Original String: " + my_string)
my_string = string.replace(my_string, '#', '')
print("After Replacement: " + my_string)
my_list = my_string.split('a')
print("my_list is " + str(my_list))
--------------------------------------------------
TestRun:
--------------------------------------------------
$ ./prog.py
Original String: 12a#43a5#6a9a#32
After Replacement: 12a43a56a9a32
my_list is ['12', '43', '56', '9', '32']
$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.