Question: Write a function in python called num _ halves that takes a positive number as input, and that uses a while - loop to count

Write a function in python called num_halves that takes a positive number as input, and that uses a while-loop to count and return the number of times we need to halve the number before it becomes smaller than 0.1.
For example, starting with the number 20, we get
20-:2=10
10-:2=5
5-:2=2.5
2.5-:2=1.25
1.25-:2=0.625
0.625-:2=0.3125
0.3125-:2=0.15625
0.15625-:2=0.078125
That took 8 halvings to get below 0.1, so calling num_halves(20) should return 8.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!