Ethan H.

asked • 03/02/21

Loop 3.5 questions

Note: they use xrange in the book we will use range

  1. Translate the following for loops to equivalent while loops.
  2. a.  for count in range(100):

            print count

       b. for count in range(1, 101):

            print count

       c. for count in range(100, 0, -1):

            print count

  1. The factorial of an integer is the product of all of the integers between 1

    and N, inclusive. Write a while loop that computes the factorial of a

   given integer N.

  1. The log2 of a given number is given by in the equation = 2M.

   The value of is approximately equal to the number of times can

   be evenly divided by 2 until it becomes 0. Write a loop that computes

   this approximation of the log2 of a given number N.

  1. Describe the purpose of the break statement and the type of problem

    for which it is well suited.

  1. What is the maximum number of guesses necessary to guess correctly a

    given number between the numbers and M?

  1. What happens when the programmer forgets to update the loop control

    variable in a while loop?

v

1 Expert Answer

By:

Patrick B. answered • 03/02/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.