Question: Use Python Programming Language Question 2 ( a ) A genRandomintSeq ( m ) function is defined as below, to generate a sequence of integers

Use Python Programming Language
Question 2
(a)
A genRandomintSeq (m) function is defined as below, to generate a sequence of
integers from 1 until m.
# Importing random() function from random module
# that generates a floating number from 0.01.0
# (including 0.0, but not 1.0)
from random import random
def genRandomintSeq (m) :
# There are errors in the codes below
s=set()
while True:
# Generate a random integer from 1im
i=(random()**m)+1
if i not in s :
s. add (i)
yield i
When the function is used in codes below, a sequence of five integers should be
printed in random order, for example, "RandomlntSeq=[43512]".
# There is no error in the codes below
print ('RandomIntSeq=[', end='')
for j in genRandomintseq (5) :
print (j, end='')
print (']')
Since there are some errors in how the function is defined, the expected output is not
obtained. What is the output with the current erroneous codes? Explain why such
output is obtained instead. Give the corrected codes, how the function should be
defined, so that the correct output (for example, "RandomintSeq=[43512]") can be
obtained.
 Use Python Programming Language Question 2 (a) A genRandomintSeq (m) function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!