Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code aims to check whether a number is prime and find the total number of prime numbers less than 10,000. However, the

 

The following code aims to check whether a number is prime and find the total number of prime numbers less than 10,000. However, the output is 9999 which is wrong. Could you please explain why the output is 9999? Could you please revise and optimize this code? Also explain precisely why you have done these revisions. Optimizing the code means to avoid the unnecessary steps or the codes can write a more concise way. yes str("This is a prime number.") nostr("This is not a prime number.") def prime (number): for divisor in range (2, number // 2 + 1): if number divisor == 0: return yes return no def prime_10k (): count = 0 n = 10000 for x in range (1, n): if prime (x): count = count+1 print ("The number of prime numbers under", n, "is", count) prime 10k () [15 marks]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The code provided has a few issues that are causing incorrect output Here are the problems and the revised code 1 Indentation The code block inside th... 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

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

More Books

Students also viewed these Programming questions