Python python circle of small ape final exam test questions (b)

Fast approaching the final exam, little friends are anxious not started yet? Hanging branches how to do? If you are lucky to see the small series of articles, you are smiling now, Xiao Bian summed up: General python final exam to test the contents of their favorite teachers, better than some good-looking ah, strive to achieve python hanging branches; there are summer immediately to a small partner who can spare the occasion to see a small ape circle video , to find a job after mat mat foundation, it is also very good, if you do not see a possible small series of brief look at the previous article.

First, the choice

1, python unsupported data types (C)

  A、char   B、int   C、float  D、list

2、kvps={"1":1,"2":2} ( D )
thecopy=kvps
kvps['1']=5
sum=kvps['1']+thecopy['1']
print sum

A、1 B、2 C、7 D、10

3. Which of the following is not legal Boolean expression (B)

A、x in range(6) B、3=a C、e>5 and 4==f D、(x-6)>5

4, on the python in the plural, the following statement is wrong (B)

A, represents a complex grammar is real + image j

B, the real and imaginary parts are floating,

C, the imaginary part of the suffix j and j must be case-insensitive

D, the method returns the complex conjugate complex conjugate

5, the following statement can not create a dictionary of (C)

A、dict={}

B、dict2={123:345}

C、dict3={[123]:'hello'}

D、dict4={(1,2,3):'hi'}

Second, fill in the blank

1, the known x = list (range (20)), then execute the statement x [: 18] value is a list of x = [] after ____. ([18, 19])

2, it is known formatter = 'good {0}'. Format, then the expression list (map (formatter, [ 'morning'])) ________ value. ([ 'Good morning'])

3, the expression chr (ord ( 'a') ^ 32) the value _______. ( 'A')

4, Python standard library ___________ interface provides access SQLite databases. (Sqlite3)

5, the expression re.search (r '\ w *? (? P \ b \ w + \ b) \ s + (? P = f) \ w *?', 'Beautiful is is better than ugly.'). Group (0) _ value. ( 'Is is')

Third, the short answer questions

1, write a function to convert IP addresses to achieve an integer.

As 10.3.9.12 conversion rules:

00001010 10
. 3 00000011
. 9 00001001
12 is 00001100
or more spliced together and then calculates a decimal-binary results: 0,000,101,000,000,011 0,000,100,100,001,100 =?

----

def func(x):

  lis = x.strip().split('.')

  li = [bin(int(i)) for i in lis]

  li2 = [i.replace('0b',(10-len(i))*'0') for i in li]

  return int(''.join(li2),2)
ret = func('10.3.9.12')

print(ret)

2, find the results:

v1 = 1 or 3 -------------->1

v2 = 1 and 3-------------->3
v3 = 0 and 2 and 1-------->0
v4 = 0 and 2 or 1--------->1

v5 = 0 and 2 or 1 or 4---->1

v6 = 0 or Flase and 1----->False

3, Python inside the search () and match () of the difference?

match () function is not only to detect RE matches at the beginning of the string
search () will scan the entire string to find a match, that match () matches only successful in the 0 position only to return, if not start position matching is successful, match () returns none

4, how to send mail using Python?

python achieve send and receive e-mail function is mainly used poplib and smtplib module.

poplib for receiving mail, and smtplib responsible for sending mail.

----answer:

#! /usr/bin/env python
#coding=utf-8
import sys 
import time 
import poplib 
import smtplib 
#邮件发送函数
def send_mail(): 
    try: 
        handle = smtplib.SMTP('smtp.126.com',25) 
        handle.login('[email protected]','**********') 
        msg = 'To: [email protected]\r\nFrom:[email protected]\r\nSubject:hello\r\n'
        handle.sendmail('[email protected]','[email protected]',msg) 
        handle.close() 
        return 1
     except: 
       return 0
#邮件接收函数
def accpet_mail(): 
    try: 
        p=poplib.POP3('pop.126.com') 
        p.user('[email protected]') 
        _ p.pass ( '**********')
        ret = p.stat () # returns a tuple :( number of messages, message size) 
        # p.retr ( 'message number') :( tuple returns a status information message, the message size) 
    the except poplib.error_proto, E: 
        Print "the Login failed:", E 
        the sys.exit (. 1) 

# current file when running, perform the function accpet_mail sendmail and 
IF the __name__ == "__main__": 
    the send_mail () 
    accpet_mail ()                    

This set of questions on here, how about we do, ah, if there is no pressure, it is estimated that python you this semester is still pretty good, if a bit difficult, it would have to seize the time to review the matter, because this problem individual title a bit difficult, Behold no good review can be small ape circle to see their own weaknesses to re-listen to lectures in preparation for the final exam, I hope we will test the Mongolian's all right!

 

Guess you like

Origin www.cnblogs.com/xiaoyuanquan/p/10949215.html