Python detects if it is prime

Source: Internet
Author: User

Python detects if it is prime
    编写python脚本,使得实现以下功能:    输入一个整数,通过脚本判断出输入的这个数是否是质数,然后输出是否是质数。    脚本如所示:
num = input (" Please input a integer: ") i = 2while i < Num: if Num% i = = 0: print " {} is not a prime number! ". Format (Num) break else:i + = 1if i = = Num: print  "{} is a prime number!". Format (Num) else: passprint Span class= "hljs-string" > "\ n"            
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

Run the script as shown in the following:

    是10 以内的质数判断。

Python detects if it is prime

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.