Python期末考试题

Python期末考试题
Python期末考试题

Section 1

1.You are doing a survey and need to store the values of responses from your respondents. The

values are integers from 0 to 10, inclusive. What is the minimum number of bits you need to

store each value?

a. 3 bits

b.* 4 bits

c. 5 bits

d.10 bits

e.32 bits

2.The string “I love studying for final exams!” is stored in an array of characters called lies. What is

the value of lies[3]?

a.‘l’

b.* ‘o’

c.‘v’

d.‘e’

e.‘love’

3.Consider the following pseudo code. What condition needs to be added at *CODE HERE* for the

algorithm to correctly find the minimum in an array A?

Input:

A // array of integers

n // number of elements in array

Output:

Min // value of smallest element

Minimum(A, n) // name of algorithm

Min = A[0] // initialize min as first el.

for i = 1 to n-1

if *CODE HERE* then

Min = A[i]

endif

endfor

return Min

endMinimum

a.* A[i] < Min

b.A[i] > Min

c.A[i] >= Min

d.A[i] == Min

e.A[i] = Min

4.Suppose we have a list with variable name myList. The list contains [1, 2, 3, 4, 5]. What will the

list contain if we call myList.append(6) in Python?

a.[6, 1, 2, 3, 4, 5]

b.* [1, 2, 3, 4, 5, 6]

c.[1, 2, 3, 4, 5]

d.append is not a valid list method and cannot be used.

e.It will return a syntax error.

5.Recall Project 4 where you were asked to implement Convolve2D and Scale. Recall that

Convolve2D took a 3x3 kernel K and that Scale used a scale factor scf. If we were to use

Convolve2D in our implementation of Scale, what kernel would we use?

a.K = [ [ 0, 0, 0 ] , [ 0, 0, 0 ] , [ 0, 0, 0 ] ]

b.K = [ [scf, scf, scf ] , [scf, scf, scf ] , [scf, scf, scf ] ]

c.K = [ [scf/9, scf/9, scf/9 ] , [scf/9, scf/9, scf/9 ] , [scf/9, scf/9, scf/9 ] ]

d.* K = [ [ 0, 0, 0 ] , [ 0, scf, 0 ] , [ 0, 0, 0 ] ]

e.K = [ [scf, scf, scf ] , [scf, 0, scf ] , [scf, scf, scf ] ]

6.Consider the following recursive Python function. The function does not compute the factorial,

as intended. Which of the following statements are true?

# this function computes factorial

def Fact(n):

return n * Fact(n-1)

I. The function is missing a termination condition.

II. The function does not call itself recursively.

III. The function should return 1 if n==1.

IV. The return statement is not necessary.

V. The function will run for too long, making too many recursive calls.

a.I and II

b.I and III

c.I, II, and III

d.* I, III, and V

e.II and IV

Section 2

PART 1:

Q1. Which statements regarding recursion are true:

I.Recursion is implemented with a function calling itself with subset of original input as its input II.Recursion is implemented with a function calling itself with the original input as its input

III.Every recursive algorithm has an iterative solution

IV.Recursive algorithm must have a base case or terminating condition

a.I, II, III

b.I, II, III, IV

c.*I, III, IV

d.II, III

e.III, IV

Q2. Convert hexadecimal number “201” into decimal.

a.127

b.*513

c.401

d.101

Q3. What is the expression for the following expression tree:

a. ((5 + (z / -8)) * (4 ^ 2))

b. (((5 + z) / (-8 * 4)) ^ 2)

c. ((5 + ((z / -8) * 4)) ^ 2)

d. *(((5 + z) / -8) * (4 ^ 2))

PART 2:

Q1. Suppose you have a file named “test” containing the following 3 lines:

To whom it may concern:

I am not selling my textbooks.

Seriously.

What is the output of the following function:

def my_func():

file = open("test","rt")

contents = file.read()

print contents[11:12]

file.close()

a.* m

b. a

c.y

d.ma

e.ay

Section 3

1.

What is the result of the following Python code, given that parameters a and b are positive integers? def function(a,b):

for i in range(b):

a = a+1

return a

a. a+a

b. b-a

c. a-b

d. (*) a+b

2.

What is the result of the following Python code, given that parameters a and b are positive integers?

def function2(a,b):

result = 0

for i in range(b):

result = result + a

return result

a. a*a

b. (*) b*a

c. a-b

d. b/a

3.

What is the purpose of the following Python code, given that parameter a is a positive integer?

import math

def function3(a):

sqa = (int) (math.sqrt(a))

if sqa * sqa == a:

return True

return False

a. returns True if a is even

b. returns True if a is odd

c. *returns True if a is a perfect square

d. returns True if a is prime

6.

What is the purpose of the following Python code, given that input list is a list of integers?

def function6(list):

for i in range(len(list)-1):

if(abs(list[i]-list[i+1])>1):

return False

return True

a. returns True always

b. returns True if list size is even

c.returns True if numbers in list are in ascending order

d. * returns True if difference between neighboring numbers is no more than 1

1. How many different values can a one byte memory location have?

A. 2

B. 8 *

C. 256

D. 65,536

E. 4,294,967,300

2.Which of the following is the decimal value of the binary number 1110?

A. 10

B. 12

C. 13

D. 14

E. 15

3. What is the output produced by this code snipet below.

x = 3

if 2 > x :

print 'First'

else :

print 'Second'

if 2 > x :

print 'Third'

print 'Fourth'

print `Fifth'

A.* Second

Fourth

Fifth

B.Second

Third

Fifth

C.First

Second

Third

D.Fifth

E.First

Fifth

5. What is the output of func(5) for the following codes:

def func(n):

if n == 1:

return 1

if n == 2:

return 2

return func(n – 1) + func(n – 2)

a. 6

b.7

c.* 8

d.9

e.10

1) A number is represented in binary as 0100 1100. What is its equivalent hexadecimal representation?

a) *4C

b) 10F0

c) 410

d) 4D

2) Consider the following recursive algorithm to find the length (i.e. the number of nodes) in a linked list. Fill in the blank in the algorithm with the best option to find the length of the inked list correclty.

LinkedListLength(L)

if (L == Null)

return 0

else

return ________________

a) *1 + LinkedListLength(L.next)

b) LinkedListLength(L.next)

c) LinkedListLength(L)

3) A complete binary tree is one where all internal nodes have both the left and right children, i.e., neither link is null and all levels are filled. For a complete binary tree with 31 nodes, how many levels does the tree have?

a) *5

b) 4

c) 16

d) 15

4) What is the purpose of the *import* statement in Python?

a) * Allows the use of functions defined in other modules

b) Creates and names a new module.

c) Restricts the use of functions defined in the current module.

5) The following Python function prints out only the even numbers out of a given list.

import math

def func(list):

for x in list:

if(_______):

print x

Which of the following conditions can be used in the *if* statement?

a) x%2 == 0

b) x%2

c) x is even

d) x/2

6) What is the output of the following Python function? def func(str):

str = str.replace("apples", "oranges")

print(str)

str = "apples are not oranges"

func(str)

print(str)

a) *oranges are not oranges

apples are not oranges

b) apples are not oranges

oranges are not oranges

c) oranges are not oranges

oranges are not oranges

d) apples are not oranges

apples are not oranges

Section 6

Part 1

1. Order the following running times from fast to slow:

I. n II. log(n) III. nlog(n) IV. n2

a. I, II, III, IV

b. IV, I, II, III

c. *II, I, III, IV

d. II, III, I, IV

e. none of the above

2. What is the hexadecimal representation of the following binary number: 0101 1101 0001 0100

a. 6C18

*b. 5D14

c. 5E18

d. 6C14

e. none of the above

Part 2

1. Consider the following piece of python code:

def func(a):

b=eval(input('please type in a number:'))

c=a*b

return c

What is the output for the call func(5)and the user enters 2?

a. 2

b. 5

*c. 10

d. The program will produce an error

e. 52

2. Consider the following piece of python code:

def func(A):

sum = 0

for i in range(3):

sum = sum + A[i][2]

return sum

What is the return value of func([[1,2,3],[4,5,6],[7,8,9]])

a. 45

b. 19

*c. 18

d. 24

e. none of the above

3. Consider the following piece of python code:

count = 0

str = "No"

while str[0].lower() != 'Y'.lower():

print("The count is:",count)

count = count + 1

str = input("stop? Yes or No:")

print("while loop ended")

Which of the following input strings CANNOT end the while loop

a. “Yes!”

b. “Yeap!”

c. “yep”

d. * “End”

e. “Yuck”

Section 7

Part I

Question 1:

1.Sometime we are interested in swapping two variables without

using any temporary variable. The two variables a and b are

swapped as follows

a)a=a+b

b=a-b

a=a-b

b)a=a*b

b=a/b

a=a/b

c)Neither

d)*Both (a) and (b)

Question 2:

Consider a new type of tree in which each internal node has exactly four children. How many nodes at most are there on level 4, where level 0 corresponds to the root, level 1 corresponds to the children of the root, level 2 corresponds to the children of the children of the root, etc.?

a)16

b)64

c)*256

d)1024

e)None of the above

In computer science, binary numbers are used since computer hardware can easily represent 2 states. Assume that in 2050 a technological breakthrough will allow representing 3 states in hardware. What is the base 3 representation of the decimal number 12?

a)12

b)* 110

c)120

d)1100

e)None of the above

Part II

Question 1:

What is the output of the following python program?

def myFun(x, y, z):

if(z == 1):

return (x + y)

else:

return (y + x)

print(myFun(‘U’, myFun(‘V’, ‘Z’, 1), 0))

a)UVZ

b)UZV

c)VUZ

d)*VZU

e)None of the above

What is the output of the following python code? x = 10

def myFun(y):

x = y + 1

return x

myFun(x)

x = x+2

print(x)

a) 10

b) 11

c)* 12

d) 13

What is the output of the following python program?

def myFun(x):

x = x +1

return x

x = 10

x = x+1

myFun(x)

x = x+2

print(x)

a) 10

b) 11

c)*13

d) 14

Section 8

Correct answers are marked in red.

1.In order to use a function in your code from a different file, which line of code do you have to

have at the beginning of your file?

a.import filename

b.from filename import *

c.import from filename *

d.both a and b can be used

2.Which of the following recursive functions will accurately return the factorial of a number

passed as a parameter?

a.

def factorial(n)

if (n > 1)

return 1

else

return n * factorial(n-1)

b.

def factorial(n)

if (n <= 1)

return 1

else

return n * factorial(n-1)

c.

def factorial(n)

if (n <= 1)

return factorial(1)

else

return n * factorial(n-1)

d.

def factorial(n)

if (n <1)

return 0

else

return n * factorial(n-1)

3.What is the value of T[3][1] if T = [[24,1,2],[3,-1,3],[32,4,-1]]?

a. 4

b.32

c. 2

d.Index out of range

4.In order to take a string as user input for a program you can use the following line of code:

https://www.360docs.net/doc/036378098.html, = eval(input("What is your name?”))

https://www.360docs.net/doc/036378098.html, = input("What is your name?”)

https://www.360docs.net/doc/036378098.html, = eval("What is your name?”)

d.both a and b are ok to use

5.In order to append a node to a linked list in constant time you need:

a. A while loop

b. A for loop

c. A reference to the end of the list

d. A reference to the beginning of the list

6.If you convert 101 from binary to hexadecimal you get:

a. A

b. 4

c. 5

d. C

Section 9

The answer key is provided at the end of the section.

1. Which of the following statements is true?

A. A for loop can sometimes, but not every time, be replaced with a while loop.

B. A recursive algorithm can always be replaced with an iterative algorithm.

C. An iterative algorithm always works in linear time.

2. How many bits per symbol do you need to encode a set of 37 symbols?

A. 3

B. 4

C. 5

D. 6

3. What's wrong with the following recursive algorithm?

#This function is supposed to print the answer to the current problem

#and then print the answer to the next problem

def answerToExamQuestion(b):

printAnswerTo(b)

return answerToExamQuestion(b)

A. The word 'return' is not part of the Python language.

B. It will run forever and never finish the task.

python期中考试试卷

《Python 程序设计》期中考试卷 一、填空题(每空1分,共40分) 1.Python 使用符号 标示注释;还有一种 叫做 的特别注释。 2.可以使用 符号把一行过长的Python 语句分解成几行;多个语句也可以写在同一行,语句之间要用 符号隔开。 3、每一个Python 的 都可以被当作一个模块。导入模块要使用关键字 。 4、所有Python 对象都有三个特性: 、 、 。 5、Python 的数字类型分为 、 、 、 、 等子类型。 6、Python 序列类型包括 、 、 三种; 是Python 中唯一的映射类型。 7、Python 提供了两个对象身份比较操作符 和 来测试两个变量是否指向同一个对象,也可以通过内建函数 来测试对象的身份。 8、Python 的标准类型内建函数有: 、 、 、 、 等。 9、Python 的传统除法运算符是 ,地板除法运算符是 。 10、设s=‘abcdefg ?,则s[3]值是 ,s[3:5]值是 ,s[:5]值是 ,s[3:]值是 ,s[ : :2]值是 ,s[::-1]值是 ,s[-2:-5]值是 。 11、删除字典中的所有元素的函数是 ,可以将一个字典的内容添加到另外一个字典中的函数是 ,返回包含字典中所有键的列表的函数是 ,返回包含字典中所有值的列表的函数是 ,判断一个键在字典中是否存在的函数是 。

1.下列哪个语句在Python中是非法的?() A、x = y = z = 1 B、x = (y = z + 1) C、x, y = y, x D、x += y 2.关于Python内存管理,下列说法错误的是() A、变量不必事先声明 B、变量无须先创建和赋值而直接使用 C、变量无须指定类型 D、可以使用del释放资源 3、下列哪种情况会导致Python对象的引用计数增加() A、对象被创建 B、被作为参数传递给函数 C、成为容器对象的元素 D、该对象无法访问时 4、下面哪个不是Python合法的标识符() A、int32 B、40XL C、self D、__name__ 5、下列哪种说法是错误的() A、除字典类型外,所有标准对象均可以用于布尔测试 B、空字符串的布尔值是False C、空列表对象的布尔值是False D、值为0的任何数字对象的布尔值是False 6、下列表达式的值为True的是() A、5+4j > 2-3j B、3>2>2 C、(3,2)< (…a?,?b?) D、?abc? > …xyz? 7、Python不支持的数据类型有() A、char B、int C、float D、list 8、关于Python中的复数,下列说法错误的是() A、表示复数的语法是real + image j B、实部和虚部都是浮点数 C、虚部必须后缀j,且必须是小写 D、方法conjugate返回复数的共轭复数 9、关于字符串下列说法错误的是() A、字符应该视为长度为1的字符串 B、字符串以\0标志字符串的结束 C、既可以用单引号,也可以用双引号创建字符串 D、在三引号字符串中可以包含换行回车等特殊字符 10、以下不能创建一个字典的语句是() A、dict1 = {} B、dict2 = { 3 : 5 } C、dict3 = dict( [2 , 5] ,[ 3 , 4 ] ) D、dict4 = dict( ( [1,2],[3,4] ) ) 11、下面不能创建一个集合的语句是() A、s1 = set () B、s2 = set (“abcd”) C、s3 = (1, 2, 3, 4) D、s4 = frozenset( (3,2,1) ) 12、下列Python语句正确的是() A、min = x if x < y else y B、max = x > y ? x : y C、if (x > y) print x D、while True : pass

python练习题-答案

Python练习题库 By 郑红波2017-12-19 一、填空题 1.Python标准库math中用来计算平方根的函数是__________。(sqrt) 2.在Python中__________表示空类型。(None) 3.列表、元组、字符串是Python的_________(有序无序)序列。(有序) 4.查看变量类型的Python内置函数是________________。(type()) 5.查看变量内存地址的Python内置函数是_________________。(id()) 6.表达式[1, 2, 3]*3的执行结果为______________________。([1, 2, 3, 1, 2, 3, 1, 2, 3]) 7.list(map(str, [1, 2, 3]))的执行结果为_____________________。([‘1’, ‘2’, ‘3’]) 8.已知 x = 3,并且id(x)的返回值为 0,那么执行语句 x += 6 之后,表达式 id(x) == 0 的值为___________。(False) 9.已知 x = 3,那么执行语句 x *= 6 之后,x的值为________________。(18) 10.表达式“[3] in [1, 2, 3, 4]”的值为________________。(False) 11.假设列表对象aList的值为[3, 4, 5, 6, 7, 9, 11, 13, 15, 17],那么切片aList[3:7]得到的值是______________________。([6, 7, 9, 11]) ([5 for 12.使用列表推导式生成包含10个数字5的列表,语句可以写为_______________。 i in range(10)]) 13.假设有列表a = ['name', 'age', 'sex']和b = ['Dong', 38, 'Male'],请使用一个语句将这两个列表的内容转换为字典,并且以列表a中的元素为“键”,以列表b中的元素为“值”,这个语句可以写为_____________________。(c = dict(zip(a, b))) 14.任意长度的Python列表、元组和字符串中最后一个元素的下标为________。(-1) 15.Python语句''.join(list('hello world!'))执行的结果是____________________。('hello world!') 16.转义字符’\n’的含义是___________________。(回车换行) 17.Python语句list(range(1,10,3))执行结果为___________________。([1, 4, 7]) 18.切片操作list(range(6))[::2]执行结果为________________。([0, 2, 4]) 19.表达式 'ab' in 'acbed' 的值为________。(False) 20.Python 语句 print(1, 2, 3, sep=':') 的输出结果为____________。(1:2:3) 21.表达式 int(4** 的值为____________。(2) 22.达式 sorted([111, 2, 33], key=lambda x: -len(str(x))) 的值为____________。([111, 33, 2]) 23.已知列表对象x = ['11', '2', '3'],则表达式 max(x) 的值为___________。('3') 24.表达式 min(['11', '2', '3']) 的值为_________________。('11') 25.已知列表对象x = ['11', '2', '3'],则表达式max(x, key=len) 的值为___________。('11') 26.语句 x = (3,) 执行后x的值为_______________。((3,)) 27.语句 x = (3) 执行后x的值为________________。(3) 28.已知 x = {1:2},那么执行语句 x[2] = 3之后,x的值为________________。({1: 2, 2: 3}) 29.字典对象的_____________方法返回字典中的“键-值对”列表。(items()) 30.使用列表推导式得到100以内所有能被13整除的数的代码可以写作___________________________________。([i for i in range(100) if i%13==0]) 31.表达式 3 ** 2 的值为_________。(9) 32.表达式 3 * 2的值为___________。(6) 33.已知x = [3, 5, 7],那么执行语句x[len(x):] = [1, 2]之后,x的值为

PYTHON测试题

Python测试题 一、填空题 1.Python使用符号#标示注释;以缩进对齐划分语句块。 2、Python序列类型包括字符串、列表、元组三种; 字典是Python中唯一的映射类型。 3、Python中的可变数据类型有列表和字典,不可变数据类 型有字符串、数字、元组。 4、Python的数字类型分为整数、长整数、浮点、 复数等子类型。 5、Python提供了两个对象身份比较操作符is和is not来测试两个变量是否指向同一个对象,也可以通过内建函数type()来测试对象的类型。 6、设s=‘abcdefg’,则s[3]值是‘d’,s[3:5]值是‘de’, s[:5]值是‘abcdf’,s[3:]值是‘defg’,s[::2]值是‘aceg’,s[::-1]值是‘gfedcba’,s[-2:-5]值是‘’。 二、选择题 1.下列哪个语句在Python中是非法的?() A、x=y=z=1 B、x=(y=z+1) C、x,y=y,x D、x+=y 2.关于Python内存管理,下列说法错误的是()

A、变量不必事先声明 B、变量无须先创建和赋值而直接使用 C、变量无须指定类型 D、可以使用del释放资源 3、下面哪个不是Python合法的标识符() A、int32 B、40XL C、self D、__name__ 4、下列哪种说法是错误的() A、除字典类型外,所有标准对象均可以用于布尔测试 B、空字符串的布尔值是False C、空列表对象的布尔值是False D、值为0的任何数字对象的布尔值是False 5、下列表达式的值为True的是() A、5+4j>2-3j B、3>2>2 C、(3,2)<(‘a’,’b’) D、’abc’>‘xyz’ 6、Python不支持的数据类型有() A、char B、int C、float D、list 7、关于Python中的复数,下列说法错误的是() A、表示复数的语法是real+image j B、实部和虚部都是浮点数 C、虚部必须后缀j,且必须是小写 D、方法conjugate返回复数的共轭复数 8、关于字符串下列说法错误的是() A、字符应该视为长度为1的字符串 B、字符串以\0标志字符串的结束

Python测试题(题)

Python题(共100分) 一.(共18题,1题5分,共90分) 1. 以下是Python比较运算符中的等于的是( ) A. >= B. <= C. == D. = 2. Python中“假”用什么表示?( ) A. True B. false C. False D. true 3. 以下结果为True的是?( ) A. 3 >= 5 B. 4 == 4 C. 5 < 3 D. 5 != 5 4. 我们使用哪个关键字给模块起一个小名呢?( ) A. as B. import C. Python D. sa 5. 以下程序结果为False的是?( ) A. True and True B. True or False C. False and True D. True or True 6. age = 20 beauty = 95 下列程序结果为True的是?( ) A. age >= 18 and beauty >=80 B. age <= 18 and beauty >=80 C. age >= 18 and beauty <=80 D. age <= 18 and beauty <=80 7. score = 55 if score >= 90 : print(‘3个红花’) elif score >= 80 : print(‘2个红花’) elif score >= 60 : print(‘1个红花’) else : print(‘继续努力’) 成绩等级输出的结果是( ) A. 3个红花 B. 2个红花 C. 1个红花 D. 继续努力 8. 以下程序输出的结果是( ) print(‘1’ + ‘1’) A. ‘11’ B. ‘2’ C. ?一 D. 555 9. 以下程序输出的结果是( ) print(1 + ‘1’) A. ‘11’ B. 程序报错 C. 2 D. ‘2’ 10. str() 将值转化成整数 int() 将值转化成字符串 11. year = ‘2017’ 以上程序结果为'20171'的是? ( ) A. print(year + 1) B. print(str(year) + 1) C. print(int(year) + 1) D. print(year + str(1)) 12. if 条件: print(‘我是编程小达人’) 根据上述代码分析:当以下哪个 选项作为条件时, 会在猿编程IDE提示窗口输出 “我是编程小达人”( ) A. 3 <= 5 B. 4 != 4 C. 5 < 3 D. 6 == 5 13. 有代码如下: if 56 == 100: 语句1 语句2 请问执行哪些语句( ) A. 执行语句1和语句2 B. 只执行 语句1 C. 什么都不执行 D. 只执行语句 2 14. print(‘666’ == ‘666’) 执行上面代码,输出的结果是? ( ) A. True B. False C. ‘666’== ‘666’ D. 不知 道 15. 以下程序结果为True的是?( ) A. True and False B. True and True C. False and True D. False and False 16. 以下程序结果为False的是? ( ) A. True or False B. True or True C. False or True D. False or False 17. “年龄小于等于12或者性别为女” 表达正确的是?( ) A. age < 12 or gender == ‘女’ B. age <= 12 or gender = ‘女’ C. age <= 12 or gender == ‘女’ D. age < 12 or gender = ‘女’ 18. age = 25 if age >= 18: print(‘晨晨是成年人’) print(‘晨晨很胖’) 运行程序后交互窗口的显示结 果为( ) 年龄:25 A、晨晨是成年人 晨晨很胖 C、晨晨是宝宝 B、晨晨很胖 D、晨晨是成年人 二.(10分) 1. 电脑中我们向文件内写入内容的 步骤是?( ) A. 写入文件——> 打开文件— —> 关闭文件 B. 打开文件——> 写入文件— —> 关闭文件 C. 打开文件——> 关闭文件— —> 写入文件 D. 关闭文件——> 写入文件— —> 打开文件

python练习题

Python 随堂练习 说明: 1.作业分为“基础要求”和“进阶要求” 2.作业首先要在本地完成,然后可以设计在蓝鲸应用中,以 3.交互的方式完成作业,可创意发挥。如:第8题,点击运行后,即可生存图片。若无法 在蓝鲸APP中实习,请在作业中附上代码以及执行结果截图。 4.13小题有条件的同学/协会可以试试。问答题,思考后,再运行。 5.前端设计方面,可参考bootstrap中的一些控件。 一、基础要求 1.print repr(u'中国') 的运行结果是什么? 2.什么是lambda函数?并列举一个使用lambda函数的例子 3.Excel操作 将 { "1":["张三",150,120,100], "2":["李四",90,99,95], "3":["王五",60,66,68] } 写入excel如下所示: 4.简述对Python装饰器的理解,写一个简单的装饰器。 5.生成100个随机数,保存到Redis非关系型数据库中 6.写结果,说明原因 if 1 in [1,0] == True: print …a? Else: Print …b? 7.用Python写一个程序,拉取SVN上的某一个文件,修改后并提交该文件。(请与蓝鲸给开发者的SVN结合起来) 8.用Python画出y=x3的散点图

9.用Python爬取知乎热门帖的标题,并存储到MySQL中(涉及django的model知识点) 二、进阶要求 10.Python 中数组套字典的排序(用lambda实现) dict = [ {'id':'4','name':'b'}, {'id':'6','name':'c'}, {'id':'3','name':'a'}, {'id':'1','name':'g'}, {'id':'8','name':'f'} ] 排序后:[{'id': '1', 'name': 'g'}, {'id': '3', 'name': 'a'}, {'id': '4', 'name': 'b'}, {'id': '6', 'name': 'c'}, {'id': '8', 'name': 'f'}] 11.利用python计算文件MD5值 (从前台上传一个文件,后台计算MD5值后,返给前端) 12.密码加密小工具 (对于部分喜欢将自己密码存在邮箱、网盘等容易被盗的朋友,可以自己记住一个唯一的密钥,通过这个小程序和密钥产生一串加密密文再存储,减少密码被盗几率。提示:Crypto 库 a.输入自己的秘钥:123456, b.选择是: encrypt 或者decrypt, c. 输出:加密后的密文,或者解密后的明文)

【试卷一】Python一级考试练习题

青少年软件编程(Python)等级考试试卷(一级) 参考样题 一、选择题(每题2分,共50分): 1、关于Python的编程环境,下列的哪个表述是正确的? A.Python的编程环境是图形化的; B.Python只有一种编程环境ipython; C.Python自带的编程环境是IDLE; D.用windows自带的文本编辑器也可以给Python编程,并且也可以在该编辑器下运行; 2、下列的哪个软件不可以编辑Python程序? A.ipython B.Visual Studio Code C.JupyterNotebook D.scratch标准版 3、下面哪个符号是Python用来给代码做注释的? A.# B.() C.: D./

4、下面print语句,哪一个是正确的用法? A.print”(hello!)” B.print(”hello!”) C.print(”hello!') D.print(”hello”!) 5、print的作用是什么? A.在屏幕上打印出来相应的文本或者数字等; B.在打印机里打印相关文本或者数字等; C.可以用来画图; D.输出一个命令行 6、下面的哪一个命令是将数值转换为字符串? A.print() B.text() C.int() D.str() 7、下面哪一个不是Python的保留字? A.class B.if C.abc D.or

8、关于变量的说法,错误的是()。 A.变量必须要命名; B.变量第二次赋值后,第一次赋的值将被删除; C.变量只能用来存储数字,不能表示存储文字; D.在同一个程序里,变量名不能重复; 9、turtle.setup()命令中坐标的起始点是()。 A.屏幕桌面的左上角; B.屏幕桌面的右上角; C.屏幕桌面的正中间; D.屏幕桌面的最上方正中间; 10、下面的哪一个命令不是画笔控制的命令()。 A.turtle.penup(); B.turtle.pendown(); C.turtle.pensize(); D.turtle.screensize(); 11、turtle.clear()命令的作用是()。 A.清空turtle窗口,但是turtle的位置和状态不会改变; B.清空turtle窗口,turtle的位置和状态会初始化; C.清空turtle中的变量,但是turtle的位置和状态不会改变;

PYTHON测试题

PYTHON测试题

A.defines a list and initializes it B.defines a function, which does nothing C.defines a function, which passes its parameters through D.defines an empty class A. B. C. D. E. A. B. C. D. E. A. B. C. D. E. A. B. C. D. E.

A. B. C. D. E. A.syntax error B.4 C.5 D.6 E.7 A. B. C. D. E. A.7 B.12 C.24 D.36 E.48

python基础100练习题

实例001:数字组合 题目有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?程序分析遍历全部可能,把有重复的剃掉。 total=0 for i in range(1,5): for j in range(1,5): for k in range(1,5): if ((i!=j)and(j!=k)and(k!=i)): print(i,j,k) total+=1 print(total) 12345678 简便方法用itertools中的permutations即可。 import itertools sum2=0 a=[1,2,3,4] for i in itertools.permutations(a,3): print(i) sum2+=1 print(sum2) 12345678 实例002:“个税计算” 题目企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?程序分析分区间计算即可。 profit=int(input('Show me the money: ')) bonus=0 thresholds=[100000,100000,200000,200000,400000] rates=[0.1,0.075,0.05,0.03,0.015,0.01] for i in range(len(thresholds)): if profit<=thresholds[i]: bonus+=profit*rates[i] profit=0 break else: bonus+=thresholds[i]*rates[i] profit-=thresholds[i] bonus+=profit*rates[-1]

Python之Numpy模块100道测试题

1. 导入numpy库并简写为np (★☆☆ (提示:import … as …) import nu mpy as np 2. 打印numpy的版本和配置说明 (★☆☆ (提示:np.version, np.show_config) print(np.__version__) n p.show_c on fig() 3. 创建一个长度为10的空向量(★☆聞 (提示:np.zeros) Z = n p.zeros(10) prin t(Z) 4. 如何找到任何一个数组的内存大小?(★☆淘 (提示:size, itemsize) Z = n p.zeros((10,10)) prin t("%d bytes" % (Z.size * 乙itemsize)) 5. 如何从命令行得到numpy中add函数的说明文档? (★☆聞 (提示:https://www.360docs.net/doc/036378098.html,) nu mpy.i nfo(nu mpy.add) add(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, sig nature, extobj]) 6. 创建一个长度为10并且除了第五个值为1的空向量(★☆淘 (提示:array[4]) Z = n p.zeros(10) Z[4] = 1 prin t(Z) 7. 创建一个值域范围从10到49的向量(★☆淘 (提示:np.arange) Z = np.ara nge(10,50) prin t(Z) 8. 反转一个向量(第一个元素变为最后一个)(★☆☆) (提示:array[::-1])

Python练习题1以及答案

选择题 1. python程序文件的扩展名是(B) A. python B. py C. pt D. pyt 2. Python语言采用严格的“缩进”来表明程序的格式框架。下列说法不正确的是:C A. 缩进指每一行代码开始前的空白区域,用来表示代码之间的包含和层次关系。 B. 代码编写中,缩进可以用Tab键实现,也可以用多个空格实现,但两者不混用。 C. “缩进”有利于程序代码的可读性,并不影响程序结构。 D. 不需要缩进的代码顶行编写,不留空白。 3.以下叙述正确的是C A. Python3.x和Python2.x兼容 B. Python语言只能以程序方式执行 C. Python是解释型语言 D. Python语言出现的晚,具有其他高级语言的一切优点 4. 下列关于Python的说法中,错误的是(C) A. Python是从ABC语言发展起来的 B. Python是一门高级的计算机语言 C. Python是一门只面向对象的语言 D. Python是一种代表简单主义思想的语言 5.下列选项中,不属于Python特点的是( B )。 A.面向对象B.运行效率高C.可读性好D.开源 6.以下叙述中正确的是( C )。 A.Python 3.x与Python 2.x兼容 B.Python语句只能以程序方式执行 C.Python是解释型语言 D.Python语言出现得晚,具有其他高级语言的一切优点 7.下列选项中合法的标识符是( D )。 A._7a_b B.break C._a$b D.7ab 8.Python不支持的数据类型有( D )。 A.char B.int C.float D.list 9.关于Python中的复数,下列说法错误的是( B )。 A.表示复数的语法形式是a+bj B.实部和虚部都必须是浮点数 C.虚部必须加后缀j或J D.函数abs()可以求复数的模 10.函数type(1+0xf*3.14)的返回结果是( D )。 A. B. C. D.

python试卷

2016年上海市高等学校计算机等级考试试卷 二级Python语言程序设计(模拟卷) (本试卷考试时间120分钟) 一、单选题(10小题,每小题1.5分,共15分) 1. “Python 语法认为条件x<=y<=z是合法的”,此说法_______。 A. 错误 B. 是否正确,要依据y变量的情况而定 C. 正确 D. 是否正确,要依据Python版本而定 2. 从字符串s的右侧向左数的第3个字符,表示为________。 A. s[3] B. s[-3] C. s[0:-3] D. s[:-3] 3. 若有ilist=[0,1,2,3,4],则ilist*2的结果为________。 A. [0,0,1,1,2,2,3,3,4,4] B. [0,1,2,3,4,0,1,2,3,4] C. [4,3,2,1,0] D. [‘0’,’1’,’2’,’3’,’4’] 4. 下列类型中,数据不可变化的是_______。 A.列表 B.字典 C.元组 D.列表、字典、元组类型中数据都不可变化 5. 字典d={'abc':1, 'qwe':2, 'zxc':3},len(d)的结果为_____。 A.6 B. 9 C. 3 D. 12 6. 在Python中适合实现多路分支的结构是_______。 A. try B. if-elif-else C. if D. if-elseif-else 7. 用for 和______关键词可以组成循环遍历字符串中的每个字符。

A. next B. while C. in D. elif 8. 设有函数定义: def f1(a=0): print(a*100) 则以下错误的函数调用语句是_________。 A. f1( ) B. f1(30) C. f1(30)+5 D. f1(30+5) 9. 以下python代码片段: fname = 'c:\\test.txt' infile = open(fname,"r") data = infile.read() print(data) 其中”r”的含意是_______。 A. 读写模式 B. 只写模式 C. 只读模式 D. 二进制只读模式 10. _________不是类的基本特征。 A. 封装性 B. 继承性 C. 多态性 D. 公有性 二、程序填空题 ( 本大题 2 道小题,每空 2.5 分,共 20 分) 1.根据密码表将密文解密成明文 为了提高数据的安全性,可将数字数据(如银行账号等)加密成字母密文保存,在使用时再解密还原成数值(例如,密文“agKxKaKa”用本程序可解密为“20151212”)。 本题解密方法可预先约定好一组字母密码存放在元组code密码表中,code[0]~code[9]分别表示数字"0"~"9"对应的密码;输入欲解密的密文(Ciphertext)并回车(输入字母”q” 退出程序),根据密码表转换成明文(Plaintext,码表中无法转换的码用’?’代替),显示在标签上。如图所示。

最新PYTHON测试题

1.what does the following code do?(B) def a(b, c, d): pass A.defines a list and initializes it B.defines a function, which does nothing C.defines a function, which passes its parameters through D.defines an empty class 2.what gets printed? Assuming python version 2.x(A) print type(1/2) A. B. C. D. E. 3. what is the output of the following code?(E) print type([1,2]) A. B. C. D. E. 4. what gets printed?(C) def f(): pass print type(f()) A. B. C. D. E. 5. what should the below code print?(A) print type(1J) A. B. C. D. E.

python测试题

一、单项选择题 1.下列哪个语句在Python中是非法的?B A、x = y = z =1 B、x = (y = z + 1) C、x, y = y, x D、x += y 2.关于Python内存管理,下列说法错误的是B A、变量不必事先声明 B、变量无须先创建和赋值而直接使用 C、变量无须指定类型 D、可以使用del释放资源 3、下面哪个不是Python合法的标识符B A、int32 B、40XL C、self D、name

4、下列哪种说法是错误的A A、除字典类型外,所有标准对象均可以用于布尔测试 B、空字符串的布尔值是False C、空列表对象的布尔值是False D、值为0的任何数字对象的布尔值是False 5、下列表达式的值为True的是D A、5+4j >2-3j B、3>2>2 C、(3,2)<(‘a’,‘b’) D、’abc’ > ‘xyz’ 6、Python不支持的数据类型有A A、char B、int C、float D、list 7*、关于Python中的复数,下列说法错误的是C

A、表示复数的语法是real + imagej B、B、实部和虚部都是浮点数 C、虚部必须后缀j,且必须是小写 D、方法conjugate返回复数的共轭复数 8、关于字符串下列说法错误的是B A、字符应该视为长度为1的字符串 B、字符串以\0标志字符串的结束 C、既可以用单引号,也可以用双引号创建字符串 D、在三引号字符串中可以包含换行回车等特殊字符 9、以下不能创建一个字典的语句是D A、dict1 = {} B、dict2 = { 3 : 5 } C、dict3 ={[1,2,3]: “uestc”} D、dict4 = {(1,2,3): “uestc”} 11*、以下代码运行结果是什么(假设在python 2.X下)()A print type(1/2)

Python99道经典练习题答案

獨傢惜愛獨傢棄愛獨傢襲愛 #!/usr/bin/env python #coding: utf-8 ''' 【程序1】 题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。 2.程序源代码: ''' for i in range(1,5): for j in range(1,5): for k in range(1,5): if( i != k ) and (i != j) and (j != k): print i,j,k ''' 【程序2】 题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高 于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提 成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于 40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于 100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数? 1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。 2.程序源代码: ''' bonus1 = 100000 * 0.1 bonus2 = bonus1 + 100000 * 0.500075 bonus4 = bonus2 + 200000 * 0.5 bonus6 = bonus4 + 200000 * 0.3 bonus10 = bonus6 + 400000 * 0.15 i = int(raw_input('input gain:\n')) if i <= 100000: bonus = i * 0.1 elif i <= 200000: bonus = bonus1 + (i - 100000) * 0.075 elif i <= 400000:

(完整版)python真题

老男孩Python全栈7期练习题(面试真题模拟) 一、选择题(32分) 1、python不支持的数据类型有 A、char B、int C、float D、list 2. x = “foo” y = 2 print(x+y) A.foo B.foofoo C.foo2 D.2 E.An exception is thrown 3、关于字符串下列说法错误的是 A、字符应该视为长度为1的字符串 B、字符串以\0标志字符串的结束 C、既可以用单引号,也可以用双引号创建字符串 D、在三引号字符串中可以包含换行回车等特殊字符 4、以下不能创建一个字典的语句是 A、dic1 = {} B、dic2 = {123:345} C、dic3 = {[1,2,3]:'uestc'} D、dic3 = {(1,2,3):'uestc'} 5.Kvps = {‘1’:1,’2’:2} theCopy = kvps kvps[‘1’] = 5 sum = kvps[‘1’] + theCopy[‘1’] Print sum A.1 B.2 C.7 D.10 6、以下何者是不合法的布尔表达式:

A.x in range(6) B.3=a C.e>5 and 4==f D(x-6)>5 7、下列表达式的值为True的是 A.5+4j>2-3j B.3>2==2 C.e>5 and 4==f D.(x-6)>5 8、已知x=43,ch=‘A’,y = 1,则表达式(x>=y and ch<‘b’ and y)的值是 A、0 B、1 C、出错 D、True 9、下列表达式中返回为True的是: A、3>2>2 B、’abc’>’xyz’ C、0x56 > 56 D、(3,2)>(‘a’,’b’) 10、下列Python语句正确的事(多选) A、min = x if x < y else y B、max = x > y ? x : y C、if(x>y) print(x) D、while True:pass 11.若k为整形,下述while循环执行的次数为: k=1000 while k>1: print k k=k/2 A.9 B.10 C.11 D.100 12、以下叙述正确的是: A、continue语句的作用是结束整个循环的执行 B、只能在循环体内使用break语句 C、在循环体内使用break语句或continue语句的作用相同

PYTHON期中考试试卷

《Python 程序设计》期中考试卷 一、填空题(每空1分,共24分)1.Python 使用符号三引号#标示注释;还有一种叫做’’’’’’的特别注释。2.表达式1/4+2.75的值是 2.75;3、请给出计算231?1的Python 表达式2**31-1:4、给出range(1,10,3)的值(1,4,7)[1,4,7]:5、Python 的数据类型分为整型、字符串型、浮点型、复数等类型。6、Python 序列类型包括元组、序列、字典三种;字典是Python 中唯一的映射类型。7、Python 的除法运算符是/,取余运算符是%。8、设s=‘abcdefg’,则s[3]值是‘d ’,s[3:5]值是def ‘de’,s[:5]值是abcdef ’abcde’s[3:]值是‘defg ’,s[::-1]值是g 。’gfedcba’9、删除字典中的所有元素的函数是def.dict clear()返回列表的函数是key(),返回包含字典中所有值的列表的函数是values()判断键在字典中是否存在的函数是has.dict(key)get()。二、选择题(每题3分,共36分)1.下列哪个语句在Python 中是非法的?(C )B A 、x =y =z =1B 、x =(y =z +1)C 、x,y =y,x D 、x +=y 2.关于Python 内存管理,下列说法错误的是(B )A 、变量不必事先声明B 、变量无须先创建和赋值而直接使用C 、变量无须指定类型D 、可以使用del 释放资源3、(1)执行下列语句后的显示结果是什么?(A)座位号题号 一二三总分合计人 分数1021分数 10 阅卷人分数21阅卷人

python试卷.doc

Python 试卷 单选题 (每题 2分,共 30分): 1.Python 使用缩进作为语法边界 , 一般建议怎样缩进 ? ( ) A.TAB B. 两个空格 C. 四个空格 D. 八个空格 2. print 100 - 25 * 3 % 4 应该输出什么 ? ( ) A.1 B.97 C.25 D.0 3.要将 3.1415926 变成 00003.14 如何进行格式化输出 ?( ) A."%.2f"% 3.1415926 B."%8.2f"% 3.1415926 C."%0.2f"% 3.1415926 D."%08.2f"% 3.1415926 4. python my.py v1 v2形式运行脚本时,通过from sys import argv如何获 得 v2 的参数值 ? ( ) A.argv[0] B.argv[1] C.argv[2] D.argv[3] 5.哪种函式参数定义非法 ? ( ) A.def myfunc(*args, a=1): B.def myfunc(arg1=1): C.def myfunc(*args): D.def myfunc(a=1, **args): 6. Python 中有很多包管理工具 , 以下哪种不是 ? ( )

A.setuptools B.pip C.ports D.yolk 7.下列哪个语句在 Python 中是非法的? ( ) A.x = y = z = 1 B.x = (y = z + 1) C.x, y = y, x D.x+= y 8.关于 Python 内存管理,下列说法错误的是 ( ) A. 变量不必事先声明 B. 变量无须先创建和赋值而直接使用 C.变量无须指定类型 D. 可以使用 del 释放资源 9.下面哪个不是 Python 合法的标识符 ( ) A.int32 https://www.360docs.net/doc/036378098.html, C.self D.40XL 10.下列哪种说法是错误的 ? ( ) A.除字典类型外,所有标准对象均可以用于布尔测试 B.空字符串的布尔值是 False C.空列表对象的布尔值是 False D. 值为 0 的任何数字对象的布尔值是False 11.下列表达式的值为 True 的是 ( ) A. 5+4j > 2-3j B. 3>2>2

相关主题
相关文档
最新文档