Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Please see attachment

Delete the break at line
The following code has an error. It is currently
printing:
[3, 5, 5, 5, 7, 7, 7, 7, 7, 9]
Align the indent of the else block at line D with the
for at
And it should be printing:
line A
[2, 3, 5, 7]
What change should be made to fix the code:
Change the if condition at line
to:
def primes (up_to):
result = []
for n in range(2, up_to):
for x in range(2, n):
if n % x !- 0
# (A)
# (B)
if n % x == 0:
break
# (C)
else:
# (D)
result.append (n)
return result
Change the if condition at line
to:
print(primes(10))
if x % n == 0
expand button
Transcribed Image Text:Delete the break at line The following code has an error. It is currently printing: [3, 5, 5, 5, 7, 7, 7, 7, 7, 9] Align the indent of the else block at line D with the for at And it should be printing: line A [2, 3, 5, 7] What change should be made to fix the code: Change the if condition at line to: def primes (up_to): result = [] for n in range(2, up_to): for x in range(2, n): if n % x !- 0 # (A) # (B) if n % x == 0: break # (C) else: # (D) result.append (n) return result Change the if condition at line to: print(primes(10)) if x % n == 0
Expert Solution
Check Mark
Step 1

CODE(SCREENSHOT) :

 Computer Engineering homework question answer, step 1, image 1

Explanation : 

in line 1 , function is defined.

in line 2 , an empty list is declared.

in line 3 , a for loop is used which goes from 2 to the number.

in line 4 , another for loop is used which goes from 2 to the previous loop variable 'n'.

in line 5 , check if n is divisible by any number from 2 to that number - 1 than break out of loop.

in line 6 , an else statement is used with the second for loop to append the prime number to list.

in line 10 , the list is returned.

in line 12 , the function is called and the list is printed. 

Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY