西安石油大学Python期末复习

Python期末复习

 

一、单选题

1. Python语言属于(C)

A.机器语言    B.汇编语言    C.高级语言    D.以上都不是

2.Python 解释器环境中,用于表示上一次运算结果的特殊变量为(B)

A.  :     B.  _     C.  >    D.#

3.为了给整型变量x、y、z赋初值10,下面正确的Python赋值语句是(C)

A. xyz=10     B. x=10y=10z=10    C. x=y=z=10    D. x=10,y=10,z=10

4.Python表达式中,可以使用(A)控制运算的优先顺序

扫描二维码关注公众号,回复: 15578395 查看本文章

A.圆括号()   B.方括号[]   C.花括号{}   D.尖括号<>

5.下面if语句统计满足“性别(gender) 为男、职称(rank) 为副教授、年龄(age)小于40岁”条件的人数,正确的语句为(B)

A. if(gender== "男" or age < 40 and rank == "副教授"): n+=1

B. if(gender =="男" and age<40 and rank== "副教授"): n+=1

C. if (gender =="男" and age<40 or rank== "副教授"): n+=1

D. if(gender =="男" or age<40 or rank=="副教授"): n+=1

6.下面if语句统计“成绩(score) 优秀的男生以及不及格的男生”的人数,正确的语句为(C)

A. if(gender=="男" and score<60 or score>= 90): n+=1

B. if (gender=="男" and score<60 and score>= 90): n+=1

C. if (gender =="男" and (score<60 or score> =90)): n+=1

D. if(gender =="男" or score<60 or score>=90): n+=1

7.以下for语句结构中,不能完成1~10的累加功能的是(A)

A. for i in range(10,0): total += i

B. for i in range(1,11): total += i

C. for i in range(10,0,-1): total+=i

D. for i in (10,9,8,7,6,5,4,3,2,1): total += i

8.Python语句print(type(1/2))的输出结果是(C)

A. <class 'int'>    B. <class 'number'>    C. <class 'float>    D. <class 'double'>

9.Python语句print(chr(65)的运行结果是(D)

A.65      B.6      C. 5      D. A

10.关于Python字符串,下列说法错误的是(B)

A.字符即长度为1的字符串

B.字符串以\0标志字符串的结束

C.既可以用单引号,也可以用双引号创建字符串

D.在三引号字符串中可以包含换行回车等特殊字符

11.Python语句nums = set([1,2,2,3,3,3,4]);print(len(nums))的输出结果是(C)

A.1     B.2      C.4     D.7

12.Python语句d={1:'a',2:b',3:'c'}; print(len(d))的运行结果是(C)

A.0     B.1      C.3     D.6

13.Python程序中假设字典d= {'1':'male', '2':'female'}, 如果语句中使用d[3], 则解释器将抛出(C)错误信息

A. NameError     B. IndexError     C. KeyError     D. TypeError

14.Python中,若def fl(p, **p2): print(type(p2)),则fl(1, a=2)的程序运行结果是(C)

A. <class 'int '>     B. <class 'type'>      C. <class 'dict'>     D. <class 'list'>

二.填空题

1. Python语言是一种解释型、 面向对象的计算机程序设计语言。

2.要关闭Python解释器,可使用quit()命令或快捷键Ctrl+Z

3.Python使用符号\(反斜杠)转译字符。

4.Python表达式4.5/2的值为2.25;Python表达式4.5//2的值为2.0;Python表达式5%2的值为1.0

5. Python表达式12/4-2+5*8/4%5/2的值为1.0

6.Python无穷循环while True:的循环体中可用break语句退出循环

7.Python的4种内置的数值类型为整数类型(int),布尔类型(bool),浮点类型(float),复数类型(complex)

8.Python语句s= [1, 2, 3, 4];s.append([5,6]);print(len(s))的运行结果是5

9. Python语句print(1,2,3,4,5,sep='-',end='!')的结果是1-2-3-4-5!

10.Python语言中,使用sys模块中的sys.stdinsys.stdoutsys.stderr可以查看对应的标准输入、标准输出和标准错误流文件对象。

11.自定义异常类一般继承于Exception或其子类。

12.变量按其作用域大致可以分为全局变量,局部变量类型成员变量

程序填空

  1. def  getValue(b,r,n)

return v

  1. max_v=b

  for x in c

  max_v =x

  return max_v

  if x<min_v

程序设计

if a>0 and b>0 and c>0:

  if a+b>0 and a+c>0and b+c>0

    length=(a+b+c)

    h=length/2

    s=math.sqrt(h*(h-a)*(h-b)*(h-c))

  else:

     print(‘不能构成三角形’)

else:

print(‘Error Data’)

猜你喜欢

转载自blog.csdn.net/shaozheng0503/article/details/131457562
今日推荐