Suppose I want a random floating point number in the range [-3.5 ... +4.5] Which code fragment generates an appropriate random number? (assume the random module has been imported)
Answer in Python script
Python script and output screen is provided below:
To get a random floating point number in a particular given range , random.uniform(x, y) function can be used here, Using this function it will print any floating point number within the range x and y.
So, Python script to get a random floating point number in the range [-3.5 ... +4.5] is :
#Importing the random module
import random
# using random.uniform() function
print("Random floating point number between the range -3.5 and 4.5 is: ", random.uniform(-3.5, 4.5))
Output screen:
Thank you!!! keep coding. Good luck :)
Get Answers For Free
Most questions answered within 1 hours.