Evaluate the maximum common approx. and evaluate the prime number using Python
This article describes how to evaluate the maximum common number and determine the prime number in Python. Share it with you for your reference. The specific implementation method is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 |
#! /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 # The following else statement will pop out when break jumps out. Count-= 1 Else: Print num, "is prime" For eachNum in range (10, 21 ): ShowMaxFactor (eachNum) |
The running result is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 |
Largest factor of 10 is 5 11 is prime Largest factor of 12 is 6 13 is prime Largest factor of 14 is 7 Largest factor of 15 is 5 Largest factor of 16 is 8 17 is prime Largest factor of 18 is 9 19 is prime Largest factor of 20 is 10 |
I hope this article will help you with Python programming.