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
Hide Time Remaining A
Maslowich

Answer:

True

Explanation:

The class Math include mathematical functions such as sin(), cos(), tan(), abs(), etc

If the given statement is not written, each of the math function will be written as (take for instance, the sin() function):

<em>Math.sin()</em>

<em></em>

But after the statement has been written (it implies that the Math library has been imported into the program) and as such each of the mathematical function can be used directly.

So instead of <em>Math.sin(), </em>you write <em>sin()</em>

5 0
3 years ago
If your computer determines the destination address of a network packet is to a remote network.
Arisa [49]

The data link layer software would replace the MAC address of the next hop or gateway when the destination address of a network packet is to a remote network.

<h3>What is a data link layer?</h3>

The data link layer is the second layer of the OSI model and it can be defined as an interface between the network and physical layer. Also, it comprises two (2) main sublayers and these include the following:

  • Logical link control (LLC) layer.
  • Media access control (MAC) layer.

In Computer networking, the data link layer software would replace the MAC address of the next hop or gateway when the destination address of a network packet is to a remote network.

Read more on data link layer here: brainly.com/question/13131540

#SPJ1

5 0
2 years ago
Explain SATA peripheral bus operation?
grin007 [14]
Peripheral Bus is not associated with the SATA function on a computer as they are not universal to each other. If you can go more into context, that would be great.
3 0
3 years ago
What type of socket should be used with an air impact wrench
Vikentia [17]
<span>Black sockets should be used, but the color is not the reason why. Chrome sockets will cause splits to form in the socket walls pretty quickly, after only a few uses. But the black sockets are that color because they have gone through a process called Parkerizing that coats the surface of the socket in order to provide more resistance when being used and protect the socket against corrosion.</span>
3 0
3 years ago
Write a program that generates 1,000 random integers between 0 and 9 and displays the count for each number. (Hint: Use a list o
masya89 [10]

Answer:

import random

count0, count1, count2, count3,

count4, count5, count6, count7,

count8, count9, i = [0 for _ in range(11)]

while i < 1000:

   number = random.randint(0,9)

   if number == 0:

       count0 = count0 + 1

   if number == 1:

       count1 = count1 + 1

   if number == 2:

       count2 = count2 + 1

   if number == 3:

       count3 = count3 + 1

   if number == 4:

       count4 = count4 + 1

   if number == 0:

       count5 = count5 + 1

   if number == 6:

       count6 = count6 + 1

   if number == 7:

       count7 = count7 + 1

   if number == 0:

       count8 = count8 + 1

   if number == 9:

       count9 = count9 + 1

   

   i = i+1

print("0's: "+ str(count0) + "\n"+ "1's: "+ str(count1) + "\n"+

"2's: "+ str(count2) + "\n"+ "3's: "+ str(count3) + "\n"+

"4's: "+ str(count4) + "\n"+ "5's: "+ str(count5) + "\n"+

"6's: "+ str(count6) + "\n"+ "7's: "+ str(count7) + "\n"+

"8's: "+ str(count8) + "\n"+ "9's: "+ str(count9) + "\n")

Explanation:

- Initialize variables to hold the count for each number

- Initialize <em>i</em> to control the while loop

- Inside the while loop, check for the numbers and increment the count values when matched.

- Print the result

5 0
3 years ago
Other questions:
  • Domain of (x+8)/(x(x+10))
    12·1 answer
  • The term integration refers to the ability to
    6·1 answer
  • Sales representatives want to capture custom feedback record details related to each Account. The sales reps want to accomplish
    12·1 answer
  • Study the images of two different fronts.
    7·2 answers
  • Write a SELECT statement that returns a single value that represents the sum of the largest unpaid invoices submitted by each ve
    5·1 answer
  • You press the F9 key to convert an object to a symbol true or false​
    12·1 answer
  • Ken has discovered that a vice president of his company has been using his computer to send data about a new product to a compet
    15·1 answer
  • A multinational organization that offers web-based services has datacenters that are located only in the United State; however,
    6·1 answer
  • In the year, , the American Department of Defense put a military research network, called ARPANET online.
    5·1 answer
  • I need help NOW with my java script!! 1. What will the code below output to the console and why? const person = {
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!