CoCalc Shared Filesexpermentinal.sagewsOpen in CoCalc with one click!
Authors: Tim Clemans SMC, Christine Miles, William A. Stein
Views : 9
%auto def sbs_is_prime(n): s = '\n<h2>Is %s prime?</h2>' % (n) s += '\nStep 1. Get the square root of %s to find the stopping point for making a list of prime numbers to check.' % (n) sqrt_of_n = float(sqrt(n)) s += '\nSquare root of %s is %s' % (n, sqrt_of_n) s += '\nStep 2. Make a list of prime numbers through %s' % (int(round(sqrt_of_n))) primes = prime_range(int(round(sqrt_of_n)) + 1) s += '\n'+str(primes) s += '\nStep 3. Check if %s is divisible by each of the above primes. If one of them divides %s then stop because %s is not prime. Otherwise %s is prime.' % (n, n, n, n) for i, prime in enumerate(primes): s += '\nStep 3.%s. Is %s divisible by %s?' % (i+1, n, prime) if n % prime == 0: s += '\nYes' s += '\nAnswer: No' return s else: s += '\nNo' s += '\nAnswer: Yes' return s
Interact: please open in CoCalc