Python several exercises (prime, Fibonacci series)

Source: Internet
Author: User

Random input Prime number:

x = Int (input ("Please enter the number:")) if x! = 1:    for I in range (2, x):        if x% i = = 0: Break    Else:        Print (x)

Find all the primes within 10W

c = 0for x in range (2,100000):    for I in range (2, int (x * * 0.5) +1):        if x% i = = 0: Break    Else:        c + = 1
   print (x)        print (c)

101 items in the Fibonacci sequence

x = 0y = 0for i in range (0, 102):    if i = = 0:       y = 1    elif i = = 1:        x = 1        y = 1    else:        tmp = Y        y = x + y        x = tmp    print (y) print (y)

  

 

Python several exercises (prime, Fibonacci series)

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.