Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started