








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









(chapter 1) When Python is running in the interactive mode and displaying the chevron prompt (>>>) - what question is Python asking you? A. What would you like to do? B. What Python script would you like me to run? C. What is your favourite color? D. What is the next machine language instruction to run? - ANSW-A (chapter 1) What will the following program print out:
x = 15 x = x + 5 print(x) A. 20 B. 5 C. 15 D. "print x" E. x + 5 - ANSW-A (chapter 1) Python scripts (files) have names that end with: A. .png B. .exe C. .py D. .doc - ANSW-C (chapter 1) Which of these words is a reserved word in Python? A. while B. payroll C. names D. pizza - ANSW-A (chapter 1) What is the proper way to say "good-bye" to Python? A. // stop B. #EXIT
C. while D. quit() - ANSW-D (chapter 1) Which of the parts of a computer actually executes the program instructions? A. Secondary Memory B. Central Processing Unit C. Main Memory D. Input/Output Devices - ANSW-B (chapter 1) What is "code" in the context of this course? A. A set of rules that govern the style of programs B. A way to encrypt data during World War II C. A sequence of instructions in a programming language D. A password we use to unlock Python features - ANSW-C (chapter 1) A USB memory stick is an example of which of the following components of computer architecture? A. Main Memory B. Central Processing Unit C. Secondary Memory D. Output Device - ANSW-C (chapter 1) What is the best way to think about a "Syntax Error" while programming? A. The computer needs to have its software upgraded B. The computer has used GPS to find your location and hates everyone from your town C. The computer is overheating and just wants you to stop to let it cool down D. The computer did not understand the statement that you entered - ANSW-D (chapter 1) Which of the following is not one of the programming patterns covered in Chapter 1? A. Conditional Steps B. Repeated Steps C. Sequential Steps D. Random steps - ANSW-D (Chapter 2) In the following code, print(98.6)
B. Addition + C. Parentheses ( ) D. Multiplication * - ANSW-C (Chapter 2) What is the value of the following expression 42 % 10 Hint - the "%" is the remainder operator: A. 2 B. 1042 C. 420 D. 10 - ANSW-A (Chapter 2) What will be the value of x after the following statement executes: x = 1 + 2 * 3 - 8 / 4 A. 4 B. 2. C. 8 D. 5.0 - ANSW-D (Chapter 2) What will be the value of x when the following statement is executed: x = int(98.6) A. 98 B. 6 C. 99 D. 100 - ANSW-A (Chapter 2) What does the Python input() function do? A. Pause the program and read data from the user B. Connect to the network and retrieve a web page. C. Read the memory of the running program D. Take a screen shot from an area of the screen - ANSW-A (Chapter 2) Which of the following is a comment in Python? A. // This is a test B. * This is a test
C. # This is a test D. /* This is a test */ - ANSW-C (Chapter 2) In the following code, x = 42 What is "x"? A. A constant B. A function C. A variable D. A Central Processing Unit - ANSW-C (Chapter 3) What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when the if statement is true? A. Start the statement with a "#" character B. Indent the line below the if statement C. Begin the statement with a curly brace { D. Underline all of the conditional code - ANSW-B (Chapter 3) Which of these operators is not a comparison / logical operator? A. == B. = C. != D. >= E. < - ANSW-B (Chapter 3) What is true about the following code segment: if x == 5 : print('Is 5') print('Is Still 5') print('Third 5') A. Depending on the value of x, either all three of the print statements will execute or none of the statements will execute B. The string 'Is 5' will always print out regardless of the value for x. C. The string 'Is 5' will never print out regardless of the value for x. D. Only two of the three print statements will print out if the value of x is less than zero. - ANSW-A
print('All done') A. Small Medium LARGE All done B. LARGE All done C. All done D. Small All done - ANSW-D (Chapter 3) For the following code, if x < 2 : print('Below 2') elif x >= 2 : print('Two or more') else : print('Something else') What value of 'x' will cause 'Something else' to print out? A. x = 2. B. x = 22 C. This code will never print 'Something else' regardless of the value for 'x' D. x = - 2.0 - ANSW-C (Chapter 3) In the following code (numbers added) - which will be the last line to execute successfully? (1) astr = 'Hello Bob' (2) istr = int(astr) (3) print('First', istr) (4) astr = '123' (5) istr = int(astr) (6) print('Second', istr) A. 6
(Chapter 3) For the following code: astr = 'Hello Bob' istr = 0 try: istr = int(astr) except: istr = - 1 What will the value be for istr after this code executes? A. It will be the 'Not a number' value (i.e. NaN) B. - 1 C. It depends on the position in the collating sequence for the letter 'H' D. The istr variable will not have a value - ANSW-B (Chapter 4) Which Python keyword indicates the start of a function definition? A. continue B. sweet C. def D. return - ANSW-C (Chapter 4) In Python, how do you indicate the end of the block of code that makes up the function? A. You put the "END" keyword in column 7 of the line which is to be the last line of the function B. You put the colon character (:) in the first column of a line C. You add a line that has at least 10 dashes D. You de-indent a line of code to the same indent level as the def keyword - ANSW-D (Chapter 4) In Python what is the input() feature best described as? A. A user-defined function B. A reserved word C. A built-in function D. A data structure that can hold multiple values using strings as keys - ANSW-C
x 20 D. def x func func - ANSW-A (Chapter 4) Which line of the following Python program will never execute? def stuff(): print('Hello') return print('World') stuff() A. print('Hello') B. stuff() C. def stuff(): D. print ('World') E. return - ANSW-D (Chapter 4) What will the following Python program print out? def greet(lang): if lang == 'es': return 'Hola' elif lang == 'fr': return 'Bonjour' else: return 'Hello' print(greet('fr'),'Michael') A. Bonjour Michael B. def Michael C. Hello Michael D. Hola \n Bonjour \n Hello - ANSW-A
(Chapter 4) What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug - so read carefully). def addtwo(a, b): added = a + b return a x = addtwo(2, 7) print(x) A. 7 B. 2 C. addtwo D. 14 - ANSW-B (Chapter 4) What is the most important benefit of writing your own functions? A. Avoiding writing the same non-trivial code more than once in your program B. To avoid having more than 10 lines of sequential code without an indent or de-indent C. Following the rule that whenever a program is more than 10 lines you must use a function D. Following the rule that no function can have more than 10 statements in it - ANSW-A (Chapter 5) What is wrong with this Python loop: n = 5 while n > 0 : print(n) print('All done') A. This loop will run forever B. The print('All done') statement should be indented four spaces C. There should be no colon on the while statement D. while is not a Python reserved word - ANSW-A (Chapter 5) What does the break statement do? A. Resets the iteration variable to its initial value B. Exits the program C. Exits the currently executing loop D. Jumps to the "top" of the loop and starts the next iteration - ANSW-C
C. Sum all the elements of a list D. Count all of the elements in a list - ANSW-C (Chapter 5) What will the following code print out? smallest_so_far = - 1 for the_num in [9, 41, 12, 3, 74, 15] : if the_num < smallest_so_far : smallest_so_far = the_num print(smallest_so_far) Hint: This is a trick question and most would say this code has a bug - so read carefully A. - 1 B. 74 C. 42 D. 3 - ANSW-A (Chapter 5) What is a good statement to describe the is operator as used in the following if statement: if smallest is None : smallest = value A. matches both type and value B. Looks up 'None' in the smallest variable if it is a string C. The if statement is a syntax error D. Is true if the smallest variable has a value of - 1 - ANSW-A (Chapter 5) Which reserved word indicates the start of an "indefinite" loop in Python? A. break B. while C. indef D. def E. for - ANSW-B (Chapter 5) How many times will the body of the following loop be executed? n = 0 while n > 0 : print('Lather')
print('Rinse') print('Dry off!') A. This is an infinite loop B. 1 C. 0 D. 5 - ANSW-C