Question: Q 4 Find the bug! 1 0 Points Grading comment: The client is furious There s a bug in their code! The client is furious
Q Find the bug!
Points
Grading comment:
The
client
is
furious
Theres
a
bug
in
their
code!
The client is furious Theres a bug in their code!
The program below is supposed to generate random samples for an experiment.
The program below is supposed to generate random samples for an experiment.
However, the client keeps trying to run the program and gets the error message,
However, the client keeps trying to run the program and gets the error message,
Error
writing
samples
to
file.
Error writing samples to file.
Find the bug or bugs in this code and correct it
Find the bug or bugs in this code and correct it
Upload a script containing your corrected program, and indicate in comments
Upload a script containing your corrected program, and indicate in comments
what you modified.
what you modified.
Given:
Given:
import random
SAMPLESFILE 'samples.txt
def main:
Call generaterandomsamples with the range of samples to generate
low high as well as the quantity of samples to produce
generaterandomsamples
def generaterandomsampleslow high, samples:
Generate the quantity of random integer samples in the range
specified low high and write to text file
try:
outfile openSAMPLESFILE, w
for in rangesamples:
val random.randintlow high
outfile.writeval
outfile.close
except IOError:
printError opening the file.
except ValueError:
printInvalid data provided.
except TypeError:
printError writing samples to file.
else:
printSuccess: Data written to file.
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
