Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions