Python Simple Small Program Exercises

Source: Internet
Author: User

1.99 multiplication Table

# !/usr/bin/python     for  in range (1,10):    is in  range (i):        + = 1        Print ("%d *%d =%-2d  " % (i, j, i*j)),    print"" 

2. Daffodils

#l = [] for in range (100,1000):    if (a/100%10) **3 + (a/ 10%10) **3 + (a%10) **3 = = A:        l.append (a)print l

3. Prime numbers

#l = [] for in range (2,101):    = 0    for  in range (2,i-1):        if i% j = = 0            := 1 break                if flag = = 0:        l.append (i)print l

4. Flashback arrangement and bubble sort

#!/usr/bin/python#!coding=utf-8List = [5,8,6,9,3,4,8,9,5,1,4]list_len=Len (list)#Flashback ArrangementL_len = LIST_LEN/2 forIinchRange (l_len): List[i],list[list_len-1-i] = list[list_len-1-i], list[i]PrintList#Bubble Sort forIinchRange (list_len-1):     forJinchRange (i,list_len):iflist[i] >list[j]: list[i],list[j]=list[j],list[i]PrintList

5. End of the number

#l = [] for in range (1,1000):    = 0    for  in range (1, i):        if i% j = = 0            :+ = J    if sum = = I:        l.append (i)print l

6. Fibonacci Sequence

#= [all] for in range (9):    + l[i+1])  Print L

Python Simple Small Program Exercises

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.