Question: The following function should return a copy of the input string with all digits removed. However it contains a logic error. What's wrong, and how
The following function should return a copy of the input string with all digits removed. However it contains a logic error. What's wrong, and how would you fix it
def removedigitss:
news
for letter in s:
if letter.isdigit:
news news letter
return news
Group of answer choices
The code adds characters if they are digits, rather than if they're not digits. The condition should be reversed.
def removedigitss:
news
for letter in s:
if not letter.isdigit:
news news letter
return news
news should be reassigned to the matching letter each time the loop finds a digit.
def removedigitss:
news
for letter in s:
if letter.isdigit:
news letter
return news
The string concatenation for news is backwards. It should be
def removedigitss:
news
for letter in s:
if letter.isdigit:
news letter news
return news
There should not be a news instead modify s directly.
def removedigitss:
for letter in s:
if letter.isdigit:
s s letter
return s
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
