1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aliya0001 [1]
3 years ago
13

Complete the function digits(n) that returns how many digits the number has. For example: 25 has 2 digits and 144 has 3 digits

Mathematics
1 answer:
ss7ja [257]3 years ago
3 0

Answer:

Step-by-step explanation:

We can get this done by using the code

def digits(n):

count = 0

if n == 0:

return 1

while (n > 0):

count += 1

n= n//10

return count

Also, another way of putting it is by saying

def digits(n):

return len(str(n))

------------------------------------------

print(digits(25)) # Should print 2

print(digits(144)) # Should print 3

print(digits(1000)) # Should print 4

print(digits(0)) # Should print 1

Doing this way, we've told the system to count the number of figures that exist in the number. If it's 1000 to 9999, then it records it as 4 digits. If it's 100 - 999, then it records it as 3 digits. If it's 10 - 99, it records as 2 digits. If it's 0 - 9, then it has to record it as a single digit.

Thanks

You might be interested in
Item 16 A sphere has a radius of 8 centimeters. A second sphere has a radius of 2 centimeters. What is the difference of the vol
Zigmanuir [339]

Answer:

672\pi \text{ cm}^3.

Step-by-step explanation:

We have been given that a sphere has a radius of 8 centimeters. A second sphere has a radius of 2 centimeters. We are asked to find the difference of the volumes of the spheres.      

We will use volume formula of sphere to solve our given problem.

\text{Volume of sphere}=\frac{4}{3}\pi r^3, where r is radius of sphere.

The difference of volumes would be volume of larger sphere minus volume of smaller sphere.

\text{Difference of volumes}=\frac{4}{3}\pi(\text{8 cm})^3-\frac{4}{3}\pi(\text{2 cm})^3

\text{Difference of volumes}=\frac{4}{3}\pi(512)\text{ cm}^3-\frac{4}{3}\pi(8)\text{ cm}^3

\text{Difference of volumes}=\frac{4}{3}\pi(512-8)\text{ cm}^3

\text{Difference of volumes}=4\pi(168)\text{ cm}^3

\text{Difference of volumes}=672\pi\text{ cm}^3

Therefore, the difference between volumes of the spheres is 672\pi \text{ cm}^3.

3 0
3 years ago
Which expression is equivalent to 2(a+3) when a equals 3<br><br>2(3)<br>5(3)<br>2(3)+3<br>2(3)+6​
sammy [17]
2(3+3) or 2(3)+6, so the answer is the third option. It’s just using the distributive property.
8 0
3 years ago
Read 2 more answers
Help me, plsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
I am Lyosha [343]

Answer:

70/29 or 2 12/29

Step-by-step explanation:

5 0
2 years ago
Y = −2 4x − 3y = 18 solved by substitution please show work so i can understand :)
ycow [4]

Answer:

Step-by-step explanation:

y = -2

4x - 3y = 18

4x - 3(-2) = 18

4x + 6 = 18

4x = 12

x = 3

(3, -2)

5 0
3 years ago
Read 2 more answers
19,000 for 2 months money earns 5%
kumpel [21]

Answer:

950 dollars

Step-by-step explanation:

3 0
3 years ago
Other questions:
  • Can someone please help me know if this answer is correct
    15·1 answer
  • Use Lagrange multipliers to find the maximum and minimum values of the function subject to the given constraint. (If an answer d
    7·1 answer
  • Find g(x), where g(x) is the translation 2 units left and 12 units down of f(x)=10x–10.
    10·1 answer
  • Eliminating Fractions from Equations
    5·1 answer
  • PLEASE HELP I HAVE THIS LAST QUESTION PLEASE!!!!
    14·1 answer
  • Find<br>a,b<br>such<br>that 7.2, a, b, 3 are in A.P.​
    7·1 answer
  • Help i dont understand i have a timer for 2 minuets...
    12·1 answer
  • Someone help me please<br><br><br> Find the measure of 0.(to the nearest tenth)
    13·1 answer
  • Use the vertex formula to find the vertex of the quadratic function ​f(x)=-x^2+2-5.
    7·1 answer
  • Can someone answer this for me
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!