



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Python Review Quiz before the final week.
Typology: Quizzes
1 / 35
This page cannot be seen from the preview
Don't miss anything!




























Marks 25.00/30. Grade 83.33 out of 100.
Correct Mark 1.00 out of 1. Flag question Question text What output will the following Python 3 program produce? x = 5 if x % 2 == 0: print (x) else: print (x, x%2) Select one: a. 5 b. 5 1 c. 2 d. 5 0
Correct Mark 1.00 out of 1. Flag question Question text What will the contents of mylist be after the following code has been executed?
mylist = [1, 4, 2, 3] mylist.append(5)
Select one: a. [1, 4, 2, 3, 5] b. [5, 1, 4, 2, 3] c. [null] d. [1, 4, 2, 3]
Correct Mark 1.00 out of 1. Flag question Question text Learning to debug can be frustrating, but it is a valuable skill that is useful for many activities beyond programming. Select one: True False
Correct Mark 1.00 out of 1. Flag question Question text For the Python program below, will there be any output, and will the program terminate? while True: while 1 > 0: break print("Got it!") break
Mark 1.00 out of 1. Flag question Question text What is the output of the following statements? pi = float(3.14159) print (pi) Select one: a. 3 b. 3. c. 3. d. 0
Incorrect Mark 0.00 out of 1. Flag question Question text What will the output of this program be when it is executed? def test_function( length, width, height): print ("the area of the box is ", lengthwidthheight) return lengthwidthheight l = 12. w = 5 h = 2 test_function(l, w, h) print ("The area of the box is ", lengthwidthheight) Select one: a. A NameError because a variable not defined
b. The area of the box is 125. c. The area of the box is 0 d. A SyntaxError due to illegal function call
Correct Mark 1.00 out of 1. Flag question Question text What is the output of the following Python statements? def recurse(a): if (a == 0): print(a) else: recurse(a) recurse(1) Select one: a. 0 b. 1 c. no output d. RuntimeError: maximum recursion depth exceeded Feedback Your answer is correct.
Correct Mark 1.00 out of 1. Flag question Question text
print (count) Select one: a. 5 b. 0 c. 10000 d. 1000
Correct Mark 1.00 out of 1. Flag question Question text A loop where the terminating condition is never achieved is called an _______ Select one: a. infinite loop b. universal loop c. while loop d. for .. ever loop
Correct Mark 1.00 out of 1. Flag question Question text What output will the following code produce? n = 10 while n != 1: print (n,end=' ')
if n % 2 == 0: # n is even n = n // 2 else: # n is odd n = n * 3 + 1 Select one: a. 10 5 16 8 4 2 b. None an error will be displayed c. 8 4 2 d. 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2
Incorrect Mark 0.00 out of 1. Flag question Question text Assume that d is a Python dictionary. What does the following Python code produce? result = dict() for key in d: val = d[key] if val not in inverse: result[val] = [key] else: result[val].append(key) Select one: a. a histogram b. an inverted dictionary c. a list of tuples d. a lookup e. a reverse lookup Feedback Your answer is incorrect.
Feedback Your answer is incorrect.
Correct Mark 1.00 out of 1. Flag question Question text Assume that d is a Python dictionary. What does the following Python code produce? d.items() Select one: a. a histogram b. an inverted dictionary c. a list of tuples d. a lookup e. a reverse lookup Feedback Your answer is correct.
Correct Mark 1.00 out of 1. Flag question Question text The Python line below causes “5 dollars” to be printed. print('%d %s' % (5, 'dollars')) Select one:
True False
Correct Mark 1.00 out of 1. Flag question Question text What is the output of the following statements? pi = int(3.14159) print (pi) Select one: a. 3 b. 3. c. 3. d. 0
Correct Mark 1.00 out of 1. Flag question Question text Which of the following types are allowed for Python dictionary keys? Select one: a. dictionary b. list c. list of dictionaries d. tuple
True False
Incorrect Mark 0.00 out of 1. Flag question Question text Assume that d is a Python dictionary. What does the following Python code produce? for k in d: if d[k] == v: return k Select one: a. a histogram b. an inverted dictionary c. a list of tuples d. a lookup e. a reverse lookup Feedback Your answer is incorrect.
Correct Mark 1.00 out of 1. Flag question Question text What is the output of the following Python program?
mylist = [ [2,4,1], [1,2,3], [2,3,5] ] total = 0 for sublist in mylist: total += sum(sublist) print(total) Select one: a. 14 b. 23 c. 0 d. 13 Feedback Your answer is correct.
Correct Mark 1.00 out of 1. Flag question Question text What is the output of the Python code below? my_list = [3, 2, 1] print(my_list) Select one: a. 0 b. {3, 2, 1} c. None d. syntax error e. [3, 2, 1] Feedback Your answer is correct.
Correct
Flag question Question text Match concepts with their definition! Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. Answer 1 Any one of the languages that people speak that evolved naturally. Answer 2 An error that does not occur until the program has started to execute but that prevents the program from continuing. Answer 3 An error in a program that makes it do something other than what the programmer intended. Answer 4 The meaning of a program. Answer 5 The structure of a program. Answer 6 An error in a program that makes it impossible to parse — and therefore impossible to interpret. Answer 7 One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language. Answer 8
Correct Mark 1.00 out of 1. formal language natural language runtime error semantic error semantics syntax syntax error token
Flag question Question text A development approach that that is intended to avoid a lot of debugging by only adding and testing small amounts of code at a time is called. Select one: a. structured development b. incremental development c. unit testing d. Systems development life cycle
Correct Mark 1.00 out of 1. Flag question Question text Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What is fin? Select one: a. A file object b. A list of characters c. A list of words d. A string that may have a newline e. A string with no newline
Feedback Your answer is incorrect.
Correct Mark 1.00 out of 1. Flag question Question text What output will the following Python script produce? def function2(param): print (param, param) def function1(part1, part2): cat = part1 + part function2(cat) chant1 = "See Me " chant2 = "See You " function1(chant1, chant2) Select one: a. See You See Me b. See Me See You See Me See You c. See Me See Me See You See You d. None it would generate an error
Correct Mark 1.00 out of 1. Flag question Question text Match concepts with their definition.
An error in a program. Answer 1 The process of finding and removing any of the three kinds of programming errors. Answer 2 Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. Answer 3 A programming language like Python that is designed to be easy for humans to read and write. Answer 4 A program that reads another program and executes it. Answer 5 A programming language that is designed to be easy for a computer to execute; also called machine language or assembly language. Answer 6 Any one of the languages that people speak that evolved naturally. Answer 7 To examine a program and analyse the syntactic structure. Answer 8 A property of a program that can run on more than one kind of computer. Answer 9 An instruction that causes the Python interpreter to display a value on the screen. Answer 10 The process of formulating a problem, finding a solution, and expressing the solution. Answer 11 bug debugging formal language high-level language interpreter low -level language natural language parse portability print statement problem solving