小猿圈python之python期末考试测试题(二)

快临近期末考试了,小伙伴们是不是又开始焦虑了呢?挂科怎么办?如果很幸运看到小编的文章,你就偷着乐吧,小编总结出:一般python期末考试老师们最爱考的内容,一定要好好看啊,争取做到python不挂科;还有暑假马上来了,小伙伴们可以在闲暇之际,看看小猿圈视频,为以后找工作垫垫基础,也是很不错的,如果没有看到一,可以翻一下小编前一篇文章。

一、选择题

1、python不支持的数据类型有 ( 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、以下哪个是不合法的布尔表达式( B )

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

4、关于python中的复数,下列说法错误的是(B)

A、表示复数的语法是real+image j

B、实部和虚部都是浮点数、

C、虚部必须后缀j且j不区分大小写

D、方法conjugate返回复数的共轭复数

5、以下不能创建一个字典的语句( C )

A、dict={}

B、dict2={123:345}

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

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

二、填空题

1、已知x = list(range(20)),那么执行语句x[:18] = []后列表x的值为____。([18, 19])

2、 已知formatter = ‘good {0}’.format,那么表达式list(map(formatter, [‘morning’]))的值为________。([‘good morning’])

3、 表达式chr(ord(‘a’)^32)的值为_______。(’A’)

4、Python标准库___________提供了对SQLite数据库的访问接口。(sqlite3)

5、表达式 re.search(r’\w*?(?P\b\w+\b)\s+(?P=f)\w*?’, ‘Beautiful is is better than ugly.’).group(0) 的值为_。(’is is’)

三、简答题

1、请编写一个函数实现将IP地址转换成一个整数。

如 10.3.9.12 转换规则为:

10 00001010
3 00000011
9 00001001
12 00001100
再将以上二进制拼接起来计算十进制结果:00001010 00000011 00001001 00001100 = ?

----

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、求结果:

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里面search()和match()的区别?

match()函数只检测RE是不是在string的开始位置匹配
search()会扫描整个string查找匹配, 也就是说match()只有在0位置匹配成功的话才有返回,如果不是开始位置匹配成功的话,match()就返回none

4、如何用Python来发送邮件?

python实现发送和接收邮件功能主要用到poplib和smtplib模块。

poplib用于接收邮件,而smtplib负责发送邮件。

----答案:

#! /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() #返回一个元组:(邮件数,邮件尺寸) 
        #p.retr('邮件号码')方法返回一个元组:(状态信息,邮件,邮件尺寸) 
    except poplib.error_proto,e: 
        print "Login failed:",e 
        sys.exit(1)

#运行当前文件时,执行sendmail和accpet_mail函数
if __name__ == "__main__": 
    send_mail() 
    accpet_mail()                    

这套题就到这里,大家做的怎么样啊,如果是毫无压力,那估计你这个学期学的python还不错哦,如果有点难度,那就要抓紧时间复习啦,因为这套题个别题有点难度,看哪没有复习好,可以来小猿圈看看,把自己的弱项重新听听课,准备迎接期末考试吧,希望大家考的都会,蒙的全对!

猜你喜欢

转载自www.cnblogs.com/xiaoyuanquan/p/10949215.html