Chapter 8 answers to exercises in Python core programming (2)

Source: Internet
Author: User

8-12. (integer) Bit operation. write a program. After the user gives the start and end numbers, the following table is displayed, showing the decimal, binary, octal, and hexadecimal representation of all integers between the two numbers. if the character is printable ASCII, print it out. If none is printable, the header in the ASCII column is omitted.

#Filename:test8-12.pydef bitop():    elist=[]    tlist=[]    start=int(raw_input("Enter begin values:"))    end=int(raw_input("Enter end values:"))    promt="%-10s DEC %-9s BIN %-11s OCT %-8s HEX"%(' ',' ',' ',' ')            flag=True    if end < 33 or start > 126:        falg=False    else:        promt+='%-8s ASCII'%(' ')    #if flag:       # print "%-10s DEC %-10s BIN %-10s OCT %-10s HEX %-10s ASCII"%(' ',' ',' ',' ',' ')        #pass    for v in range(start,end+1):        elist=[str(v),bin(v),oct(v),hex(v)]        if flag:            if v in range(32,127):                elist.append(chr(v))            else:                pass                             tlist.append(elist)          print promt    for raw in tlist:        #for x in raw:        print "%-11s%s"%(' ',(10*' ').join(raw))
            bitop()    

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.