Python asks for prime number/prime number within 100

Source: Internet
Author: User
Tags for in range

Prime number, also known as prime number, has an infinite number. A prime number is defined as the number of natural numbers greater than 1, except that 1 and itself no longer have other factors, such numbers are called prime numbers.

1list1=[]2num=03 4  forIinchRange (2,100):5      forJinchRange (2,int (i**0.5) +1):6         Print(int (i**0.5) +1)7         ifi%j==0:8              Break9     Else:Ten list1.append (i) OneNum+=1 A Print(List1) - Print(num)

Optimization

List1=[2]num=0 for in range (2,100):     for in List1:                if i%j==0:            break    Else:        List1.append (i)        num+=1print(list1)print(num)

Python asks for prime number/prime number within 100

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.