This article describes how to calculate the maximum common number and determine the prime number of a Python algorithm, for more information about how to calculate the maximum common number and determine the prime number, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:
#! /Usr/bin/env python def showMaxFactor (num): count = num/2 while count> 1: if num % count = 0: print 'largest factor of % d is % d' % (num, count) break # when the break jumps out, the following else statement count-= 1 else: print num appears, "is prime" for eachNum in range (10, 21): showMaxFactor (eachNum)
The running result is as follows:
Largest factor of 10 is 511 is primelargest factor of 12 is 613 is primelargest factor of 14 is 7 largest factor of 15 is 5 largest factor of 16 is 817 is primelargest factor of 18 is 919 is primelargest factor of 20 is 10
I hope this article will help you with Python programming.