What change should be made to fix the code: def primes(up_to): result = [] for n in range(2, up_to): for x in range(2, n): # (A) # (B) # (C) if n % x == 0: break # (D) result.append(n) else: return result print(primes(10))
What change should be made to fix the code: def primes(up_to): result = [] for n in range(2, up_to): for x in range(2, n): # (A) # (B) # (C) if n % x == 0: break # (D) result.append(n) else: return result print(primes(10))
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Please see attachment
Expert Solution
Step 1
CODE(SCREENSHOT) :
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.
Step by step
Solved in 2 steps with 2 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY