Programing in Python3 (Second Edition) _ Instance

Source: Internet
Author: User

Programming in Python3 (Second Edition) instance
    • Preface: In the process of learning Python, recommend a book, "Programming in Python3" is what I used before. The reason is that this book is very comprehensive and detailed, there are some very practical examples can be provided to the reader to learn, after learning not only know how to use, but also know how the Python code at the bottom of the system is how to achieve. Last but not least, the book has a relatively new publication time, and the content is also in keeping with the trend. I used to read the book over and over again, but did not implement the following instance on the compiler, first to fill in. The following is the example code for each chapter and the effect after successful operation.
Chapter One
#bigdigits. py 41072819import sys#coding:utf-8zero=[' * * * *, ' * * ', ' * * ', ' * * ', ' * * ', ' * * ', ' * * * * ', ']one=[' * ', ' * * ', ' * * ', ' * ', ' * ', ' * ', ' * * * * * * * *, ' * * * * ', ' * * * ', ' * ', ' * * ', ' * ', ' * ', ' * * * * * * * *, ' * ', ' * ', ' * * * ', ' * ', ' * ', ' * * * * ']four=[' * ', ' * * ', ' * * ', ' * * * * ', ' * ', ' * ', ' * ']five=[' * * * * * * * ', ' * ', ' * ', ' * * * ', ' * ', ' * ', ' * * * * * * * *, ' * * * *, ' * * *, ' * * * ', ' * * ', ' * * * ', ' * * ', ' * * * ', ' * * * * * * * ', ' * ', ' * ', ' * ', ' * ', ' * ', ' * ']eight=[' * * * * *, ' * * * ', ' * * ', ' * * * ', ' * * ', ' * * ', ' * * * ', ' * * * ', ']nine=[' ', ' * * ', ' * * ', ' * * * * ', ' * ', ' * ', ' * * * * *, ']digits=[zero,one,two,three,four,five,six,seven,eight,nine ' #列表多层嵌套tr Y:digits=input ("Please input your number:") #读入数字 the row=0 while row<7:line= "" Column=0 whi Le Column<len (digits): #确定有几位数字 number=int (Digits[column]) #读取第一个数字 If a floating-point number is entered for casting Digit=digits[nu Mber] #第一个数字对应在Digits列表中的The element line+=digit[row]+ "" "" is assigned to line for the first element of the first numeric list, and each loop adds the first element of the next number list to line, each with a different number column    Two spaces between elements in a table "" "Column+=1 print (line) row+=1except ValueError as err: #如果用户输入错误的值进行异常处理, Print err Print (ERR)

#生成随机数的网格import randomdef get_int(msg,minimum,default):#输入    while True:        try:            line=input(msg)            if not line and default is not None:                return default            i=int(line)            if i<minimum:                print("must be>=",minimum)            else:                return i        except ValueError as err:            print(err)rows=get_int("rows:",1,None)columns=get_int("columns:",1,None)minimum=get_int("minimum(or Enter for 0);",-10000,0)#最大值的默认值为1000如果输入的数大于1000,默认值为两倍的minimumdefault=1000if default<=minimum:    default=2*minimummaximum=get_int("maximum(or Enter for "+str(default)+"):",minimum,default)#双层循环输出行和列的数字row=0   while row<rows:    line=""    column=0    while column<columns:        i=random.randint(minimum,maximum)        s=str(i)        s+=" "        line+=s        column+=1    print(line)    row+=1

2018/8/10 13:27:27

Programing in Python3 (Second Edition) _ instance

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.