bennyanderson7704 bennyanderson7704
  • 22-11-2021
  • Computers and Technology
contestada

Assume you have assigned x the string value of "125,000" (i.e., x = "125,000"). Can you find a string method that tests if x only contains digits?

Respuesta :

holmtheditto
holmtheditto holmtheditto
  • 22-11-2021

Answer:

x = x.replace(',', '')

print(x.isdigit())

Explanation:

isdigit() is a built-in checking method which checks if a string contains all digit values or not. Since x contains a ',' it has to be removed and since strings are immutable, i create a new string without the comma. Then I check if it is a digit, in which case it is true.

Answer Link

Otras preguntas

Doing monomials. How do you do this one?
analogies, allow:permit::find:
How did its first pharaoh unify Egypt
A golf ball is dropped from rest from a height of 9.5m.  It hits the pavement then bounces back up rising  just 5.7 m before falling back down again.  A boy the
the school marching band has 36 members. the band director wants to arrange the band members into a square formation. how many band members should be in each ro
A rectangle is 5 units long. The rectangle is also 3 units wide. What is its perimeter?
how did other nations contribute to the american revolution?
what is the lithosphere made out of?
Sylvan withdrew 2/5 of the amount in his savings account, and spent 7/10 of that money.  What fraction of his total savings does he still have?
what is the lithosphere made out of?