In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the remaining 75% of the time. The following code segment is intended to simulate the experiment if there are 100 trials. Line 1: xCount 0 Line 2: yCount ← 0 Line 3: REPEAT 100 TIMES Line 4: { Line 5: IF(RANDOM (1, 4) = 1) Line 6: { Line 7: xCountxCount + 1 Line 8: } Line 9: IF(RANDOM (1, 4) > 1) Line 10: { Line 11: yCountyCount + 1 Line 12: } Line 13: } Line 14: DISPLAY ("Result X occurred") Line 15: DISPLAY (xCount) Line 16: DISPLAY ("times and result Y occurred") Line 17: DISPLAY (yCount) Line 18: DISPLAY("times.") A programmer runs the code segment, and the following message is displayed. Result X occurred 24 times and result Y occurred 70 times. The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following changes to the code segment will ensure a correct simulation of the experiment? A Replacing line 9 with IF (RANDOM (1, 4) ≥ 2) B Replacing line 9 with ELSE C Interchanging lines 5 and 9 D Interchanging lines 7 and 11

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the
remaining 75% of the time. The following code segment is intended to simulate the experiment if there are
100 trials.
Line 1: xCount 0
Line 2:
yCount ← 0
Line 3:
REPEAT 100 TIMES
Line 4:
{
Line 5:
IF(RANDOM (1, 4) = 1)
Line 6:
{
Line 7:
xCountxCount + 1
Line 8:
}
Line 9:
IF(RANDOM (1, 4) > 1)
Line 10:
{
Line 11:
yCountyCount + 1
Line 12: }
Line 13: }
Line 14: DISPLAY ("Result X occurred")
Line 15: DISPLAY (xCount)
Line 16: DISPLAY ("times and result Y occurred")
Line 17: DISPLAY (yCount)
Line 18: DISPLAY("times.")
A programmer runs the code segment, and the following message is displayed.
Result X occurred 24 times and result Y occurred 70 times.
The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following
changes to the code segment will ensure a correct simulation of the experiment?
A
Replacing line 9 with IF (RANDOM (1, 4) ≥ 2)
B
Replacing line 9 with ELSE
C
Interchanging lines 5 and 9
D Interchanging lines 7 and 11
Transcribed Image Text:In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the remaining 75% of the time. The following code segment is intended to simulate the experiment if there are 100 trials. Line 1: xCount 0 Line 2: yCount ← 0 Line 3: REPEAT 100 TIMES Line 4: { Line 5: IF(RANDOM (1, 4) = 1) Line 6: { Line 7: xCountxCount + 1 Line 8: } Line 9: IF(RANDOM (1, 4) > 1) Line 10: { Line 11: yCountyCount + 1 Line 12: } Line 13: } Line 14: DISPLAY ("Result X occurred") Line 15: DISPLAY (xCount) Line 16: DISPLAY ("times and result Y occurred") Line 17: DISPLAY (yCount) Line 18: DISPLAY("times.") A programmer runs the code segment, and the following message is displayed. Result X occurred 24 times and result Y occurred 70 times. The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following changes to the code segment will ensure a correct simulation of the experiment? A Replacing line 9 with IF (RANDOM (1, 4) ≥ 2) B Replacing line 9 with ELSE C Interchanging lines 5 and 9 D Interchanging lines 7 and 11
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education