Ask Question
25 November, 21:57

What expressions will initialize d with a random value such that all possible values for d are given by the inequality 1.5 ≤ d < 7.5?

+3
Answers (1)
  1. 25 November, 22:03
    0
    The solution code is written in Python

    d = 1.5 + random. random () * 6

    Explanation:

    By presuming the Python random module is imported, we can use the random method to generate a random number. random. random () will give us a value in the range [0, 1). The ensure the lower limit is 1.5 instead of 0, we can add 1.5 to random. random ()

    1.5 + random. random ()

    This expression will give any value in range [1.5, 2.5)

    To ensure the upper limit is set to 7.5, we tweak the previous expression to

    1.5 + random. random () * 6

    This expression will always multiply a random number from [0,1) with 6 and then only added with 1.5. This will always produce a random number that fulfill the inequality 1.5 ≤ d < 7.5
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What expressions will initialize d with a random value such that all possible values for d are given by the inequality 1.5 ≤ d < 7.5? ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers