Evaluate the maximum common approx. and evaluate the prime number using Python

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.