Question

Suppose I want a random floating point number in the range [-3.5 ... +4.5] Which code...

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

Homework Answers

Answer #1

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 :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the array of floating-point values called "measurements". Complete the code so it would display the...
Consider the array of floating-point values called "measurements". Complete the code so it would display the values from "measurements" that deviate from TARGET by no more than TOLERANCE. You may want to use Math static method "abs", which returns the absolute value of a given number. For example, Math.abs(-3) = 3. To be clear, the expected output of your program should be the numbers 3.51, 3.49, 3.51, and 3.5. double measurements[] = { 3.51, 3.53, 3.49, 3.51, 3.47, 3.50 };...
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
WRITE USING PYTHON PROGRAMMING THE CODE GIVEN BELOW HAS SOME ERRORS WHICH NEED TO BE SOLVED....
WRITE USING PYTHON PROGRAMMING THE CODE GIVEN BELOW HAS SOME ERRORS WHICH NEED TO BE SOLVED. ALSO THE 2 POINTS MENTIONED BELOW SHOULD BE PRESENT IN THE CODE Write a script that calculates the 3 longest words of a text stored in a file and print them from the longest to the smaller of the 3. Please note: 1. The name of the file is word_list.csv and it doesn’t need to be asked to the user (meaning the name will...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
This programming task will be a bit different. It will be more like what you would...
This programming task will be a bit different. It will be more like what you would receive if you were a maintenance engineer working in a corporate information systems or technology department. In other words, you will have some prebuilt source code provided for you that you must alter so it will meet the given programming specification.. Build a program from what you have been given as a starting-point. Rename the “starter code”. Do not add any modules; just, use...
I need the actual code for this... I found a similar response but it was not...
I need the actual code for this... I found a similar response but it was not thorough enough. Problem Prerequisites: None Suppose that a scientist is doing some important research work that requires her to use rabbits in her experiments. She starts out with one adult male rabbit and one adult female rabbit. At the end of each month, a pair of adult rabbits produces one pair of offspring, a male and a female. These new offspring will take one...
I want only the answer to Q2 and Q3 please show your work step by step...
I want only the answer to Q2 and Q3 please show your work step by step and show how did you do the graph in Q2 Q1). A specialty coffeehouse sells Colombian coffee at a fairly steady rate of 280 pounds annually. The beans are purchased from a local supplier for $2.40 per pound. The coffee house estimates that it costs $45 in paperwork and labor to place an order for the coffee, and holding costs are based on a...
1.A fair die is rolled once, and the number score is noted. Let the random variable...
1.A fair die is rolled once, and the number score is noted. Let the random variable X be twice this score. Define the variable Y to be zero if an odd number appears and X otherwise. By finding the probability mass function in each case, find the expectation of the following random variables: Please answer to 3 decimal places. Part a)X Part b)Y Part c)X+Y Part d)XY ——- 2.To examine the effectiveness of its four annual advertising promotions, a mail...
(1 point) Is college worth it? Part I Among a simple random sample of 331 American...
(1 point) Is college worth it? Part I Among a simple random sample of 331 American adults who do not have a four-year college degree and are not currently enrolled in school, 48% said they decided not to go to college because they could not afford school. A newspaper article states that only a minority of the Americans who decide not to go to college do so because they cannot afford it and uses the point estimate from this survey...