1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ryzh [129]
3 years ago
13

Consider the following code segment, which is intended to simulate a random process. The code is intended to set the value of th

e variable event to exactly one of the values 1, 2, or 3, depending on the probability of an event occurring. The value of event should be set to 1 if the probability is 70 percent or less. The value of event should be set to 2 if the probability is greater than 70 percent but no more than 80 percent. The value of event should be set to 3 if the probability is greater than 80 percent. The variable randomNumber is used to simulate the probability of the event occurring.
int event = 0;
if (randomNumber <= 0.70)
{
event = 1;
}
if (randomNumber <= 0.80)
{
event = 2;
}
else
{
event = 3;
}
The code does not work as intended. Assume that the variable randomNumber has been properly declared and initialized. Which of the following initializations for randomNumber will demonstrate that the code segment will not work as intended?
A) randomNumber = 0.70;
B) randomNumber = 0.80;
C) randomNumber = 0.85;
D) randomNumber = 0.90;
E) randomNumber = 1.00;
Computers and Technology
1 answer:
lora16 [44]3 years ago
3 0

Answer:

A) randomNumber = 0.70;

Explanation:

The code works perfectly for all values of randomNumber given in the options except option (a)

This is so because:

The first condition

<em>if (randomNumber <= 0.70)  {  event = 1;  }</em>

It checks if randomNumber is less than or equal to 0.70. This is true, so event is set to 1.

However, the next condition after it will also be executed because it is a different conditional to be executed.

So, we have:

if (randomNumber <= 0.80)  {  event = 2;  }

This condition is also true, so event is set to 2.

From the question randomNumber is meant to be event 1. However, this is different from the result of executing the code.

Hence, (a) is true

You might be interested in
Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 5
omeli [17]

Answer:

The Following are the code to this question:

def cost(miles, milesPerGallon, dollarsPerGallon):##defining a method cost that accepts three parameter

   return miles / milesPerGallon * dollarsPerGallon# calculate cost and return it value  

milesPerGallon = float(input('Enter miles/Gallon value: '))#defining variable milesPerGallon for user input  

dollarsPerGallon = float(input('Enter dollars/ Gallon value: '))#defining variable dollarsPerGallon for user input

print('{:.5f}'.format(cost(10, milesPerGallon, dollarsPerGallon)))#call method and print its value

print('{:.5f}'.format(cost(50, milesPerGallon, dollarsPerGallon)))#call method and print its value

print('{:.3f}'.format(cost(400, milesPerGallon, dollarsPerGallon)))#call method and print its value

Output:

Enter miles/Gallon value: 20.0

Enter dollars/ Gallon value: 3.1599

1.57995

7.89975

63.198

Explanation:

In the above-given code, a method "cost" is defined, that accepts three value "miles, milesPerGallon, and dollarsPerGallon" in its parameter, and use the return keyword for calculating and return its value.

In the next step, two variable "milesPerGallon, and dollarsPerGallon" is declared, that use the input method with float keyword for input floating-point value.

After input value, it uses a print method with different miles values, which are "10,50, and 400", and input value to pass in cost method to call and print its return value.

5 0
3 years ago
HURRRRYYYY
Mandarinka [93]
An example of revolving credit is C
8 0
3 years ago
Read 2 more answers
unittttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
alukav5142 [94]
What the hell is the point of this, just to waist people's time?
5 0
3 years ago
Uses computer resources from multiple locations to solve a common problem.
Lynna [10]

Answer:

Distributed Computing is used to solve common problem from multiple locations at different locations.

Explanation:

It is the architecture of processor, that is used to combine the different resources of computer from different domain to solve the common problem.

It allows us resource sharing such as hardware and software that are connected to the computer.

Examples

Following are the examples of Distributed computing.

  1. Telecommunication Network
  2. sensor network
  3. banking network

8 0
3 years ago
Five corporations own over 90 percent of the media in the US.<br> 1.True<br> 2.False
avanturin [10]
<span>Five corporations own over 90 percent of the media in the US : </span>1.True.

7 0
3 years ago
Other questions:
  • Part 3a. Largest power of two less than (10 pts) Implement the method public static int largestPow2LessThan(int n) which calcula
    5·1 answer
  • HEY DO U LIKE TRAINS!
    7·1 answer
  • What is the name of a popular high-level computer programming and scripting language that is the name of a snake?
    10·1 answer
  • According to the video, what is the goal of Film and Video Editors?
    11·2 answers
  • For each of these statements find a domain for which the statement is true and a domain for which the statement is false. a) Eve
    13·1 answer
  • Which of the following is most likely to be considered plagiarism? a. Intentionally reporting the results of inaccurate statisti
    11·1 answer
  • From the Software Engineering Code of Ethics, which clauses relate to intellectual property (check all that apply)
    15·1 answer
  • Josh wrote the following e-mail to his co-worker. PLEASE HELP QUWICK
    5·2 answers
  • Easy<br> What is your favorite Anime<br> Mine is Attack On Titan at the moment
    7·2 answers
  • How will understanding IT help me achieve my goals in life?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!