Programming Quiz 2 and Quiz 3
18 Which of the following is not an augmented assignment operator? Select one: A. *= B. != C. += D. %=
!=
28 In Python the not equal relationship operator is? Select one: a. =! b. <> c. not= d. !=
!=
4 Which statement is true based on the rules of relationship operators and comparing text using the Python language? Select one: a. "chevy" <= "Chevy" b. "Oldsmobile" = "Oldsmobile" c. "GMC" < "GMC" d. "Ford" >= "FORD"
"Ford" >= "FORD"
16 Which of the following expressions correctly determines that x is greater than 10 and less than 20? Select one: a. 10 < x < 20 b. 20 > x > 10 c. (10 < x) and (x < 20) d. (10 < x) or (x < 20)
(10 < x) and (x < 20)
4 In a range function when used in a for-loop, how many arguments can be included in the function call? Select one: a. 1 b. 2 c. 3 d. 1 ,2 or 3 .
1 ,2 or 3
15 What is the output of the following code: for num in range(3, 1, -1): print(num) Select one: a. 3 2 b. 2 3 c. 3 2 1 d. 1 2 3 .
3
20 What conditional statement is used to express the following? Both X and Y are positive or both X and Y are negative Select one: a. (X>0 or Y >0) or (X<0 or Y<0) b. (X>0 or Y >0) and (X<0 or Y<0) c. (X>0 and Y >0) and (X<0 and Y<0) d. (X>0 and Y >0) or (X<0 and Y<0)
(X>0 and Y >0) or (X<0 and Y<0)
11 What will be displayed after the following code is executed? for num in range(0, 15, 5): num += num print(num) Select one: A. 0, 10, 20 B. 30 C. 0 5 10 15 D. 5 10 15
0, 10, 20
17 What are the values that the variable num contains through the iterations of the following for loop? for num in range(1, 9, 2): Select one: A. 1, 2, 3, 4, 5, 6, 7, 8, 9 B. 1, 2, 3, 4, 5, 6, 7, 8 C. 1, 3, 5, 7, 9 D. 1, 3, 5, 7
1, 3, 5, 7
26 What is the value of the target variable m each time through the iteration of the following code: for m in {1, 4, 1}: Select one: a. 1, 2, 3 b. 1, 2, 3, 4 c. 1, 4, 1 d. This is not valid code
1, 4, 1
9 If a range function used in a for-loop has only one argument the default start value is ______ and the default step value is_________? Select one: a. The default start value is 0, and the default step value is 1. b. The default start value is 1, and the default step value is 1. c. The default start value is 1, and the default step value is 0. d. The default start value is 0, there is no default step value. .
The default start value is 0, and the default step value is 1.
8 What is the output of the following code: x = 3 y = 3 if x > y: z = x + y else: z = y - x Select one: a. 0 b. False c. 6 d. There is no output
There is no output
2 Based on the following code what Boolean value is returned from the conditional expression that follows (based on x = 5): (x > 10) or (x >= 5) and (x <= 6) Select one: a. True b. False c. This is not a valid statement for the use of the "and" an "or" operators d. There is a syntax error in the code
True
6 What is the output of the following program? x = -2 y = 7 if x != y: y = x z = y / x else: x = y z = y // x print(z) Select one: a. 1.0 b. -3.0 c. 1 d. -3
1.0
28 What is the value of the target variable num each time through the following loop code: for num in range(10, 1, -3): Select one: a. 10, 7, 4, 1 b. 1, 4, 7, 10 c. 1, 4, 7 d. 10, 7, 4
10, 7, 4
7 In the following nested loop how many iterations will the inner loop complete during execution of the code? for i in range(1, 4): for j in range(1, 5): print(j) Select one: a. 12 b. 9 c. 20 d. 5 .
12
24 To this point we have looked at the str, int and float data types. Chapter 3 introduces the Boolean datatype. How many values can a Boolean variable reference? Select one: a. 2 b. 3 c. As many as defined d. As many as needed
2
27 How many times will the loop iterate and the print statement be executed in the following code: count = 1 while count <= 5: print(count) count +=2 Select one: a. 1 b. 2 c. 3 d. 4
3
20 What will be displayed after the following code is executed? total = 0 for count in range(3,6): total += count print(total) Select one: a. 3 6 b. 3 4 5 c. 3 7 12 d. There is no output
3 7 12
12 A blank space is represented by the number ____ on the ASCII code? Select one: a. 32 b. 95 c. 46 d. It is not represented on the ASCII code only characters, numbers and symbols are represented
32
19 What will be displayed after the following code is executed? total = 0 for count in range(2,4): total += count print(total) Select one: a. 9 b. 5 c. 6 d. 2 3
5
25 In the following code how many times will the print statement be executed? for i in range(6, 0, -2): for j in range(0, 5, 2): print(j) Select one: a. 9 b. 10 c. 11 d. 12
9
16 When will the following loop terminate? while count != 9: Select one: a. when count refers to a value less than 9 b. when count refers to a value greater than 9 c. when count refers to a value equal to 9 d. when count refers to a value not equal to 9
when count refers to a value equal to 9
According to our textbook this type of loop is a condition-controlled loop. A condition-controlled loop causes a statement or set of statements to repeat as long as a condition is true. Select one: a. for-loop b. while-loop c. infinite-loop d. stop-loop .
while-loop
14 What is the output of the following code? if ("cat" > "Cat") and ("Dog" < "dog"): print("yes") else: print("no") Select one: a. yes b. no c. This is not valid code because of a syntax error d. This is not valid code because you cannot use relationship operators and logical operators in comparing text
yes
9 Consider the following 2 sets of code: Example (a): a = 1 b = 1 if (a == 1) and (b == 1): print("Hi") Example (b): a = 1 b = 1 if (a == 1): if(b == 1): print("Hi") Select one: a. Examples (a) and (b) will produce different outputs. b. Example (b) is not a valid set of Python instructions. c. The two sets of example code are equivalent d. The condition statement in Example (a) is not valid.
The two sets of example code are equivalent
15 When writing "if" statements within "if" statements in Python which of the following below is false? Select one: a. Make sure the "if" clause and the "else" clause for each "if" statement are aligned b. There needs to be a semicolon at the end of each "if" clause and "else" clause c. Any code that follows an "if" clause and "else" clause needs to be consistently indented d. The "if" clause must have a conditional expression where the "else" clause cannot have a conditional expression
There needs to be a semicolon at the end of each "if" clause and "else" clause
27 What is the Boolean output of the following code: str1="GAry" str2="gAil" NOT(str1 > str2) Select one: a. True b. False c. Not Equal d. This would produce an error because it is not valid code
True
3 An "if" block of code does not need the "else" portion of the code to be valid syntax but, if used there can only be one "else" portion? Select one: a. False b. True c. This statement is neither True or False because the first part of the statement is True and the other part of the statement is False d. This statement is neither True or False because the first part of the statement is False and the other part of the statement is True
True
10 A while loop that never ends because the programmer forgot to write code that makes the test condition false is called an __________ loop. Select one: a. continuing b. for c. infinite d. progressive .
infinite
23 and, not and or are considered _______ ________? Select one: a. relationship operators b. decision operators c. mathematical operators d. logical operators
logical operators
7 When an "if" statement is the true or false part of another "if" statement they are? Select one: a. combined if statements b. elif statements c. else if statements d. nested if statement
nested if statement
6 In the following loop code according to our textbook the target variable is? total = 0.0 count = 0 for num in range(count): total += num print(total) Select one: a. total b. num c. count d. There is no target variable .
num
5 In the following nested loop the loop code "for i in range(1, 4):" is called the ______ loop: for i in range(1, 4): for j in range(1, 5): print(j) Select one: a. main b. primary c. first d. outer .
outer
13 According to our textbook, the first input read prior to entering a loop is called the ________ and its purpose is to get the first input value that will be tested by a validation loop. Select one: A. priming read B. first input C. loop set read D. loop validation
priming read
22 Input ________ is the process of inspecting data that has been input to a program, to make sure it is correct before it is used in a computation. A loop is typical utilized for this and the loop iterates as long as an input variable references bad data. Select one: a. sequence b. count c. initialization d. validation
validation
29 When processing a long sequence of values with a loop, our textbook points out one technique to utilize is using a ________ which is a special value that marks the end of a sequence of items. When a program reads this value, it knows it has reached the end of the sequence, so the loop terminates. A _________ value must be distinctive enough that it will not be mistaken as a regular value in the sequence. Such as if you are trying to track a condition of a persons body weight, you could use zero (0) as its _______ value because no person can weigh zero (0). Select one: a. accumulator b. sentinel c. counter d. target
sentinel
26 When using the "and" operator, if the expression on the left side of the "and" operator is false, the expression on the right side will not be checked. Because the compound expression will be false if only one of the subexpressions is false, it would waste CPU time to check the remaining expression. When using the "or" operator, if the expression on the left side of the "or" operator is true, the expression on the right side will not be checked. Again, to not waste CPU time. In our textbook this is defined as ________ evaluation. Select one: a. short-circuit b. memory saving c. logical relationship d. code shortcut
short-circuit
2 In a range function when used in a for-loop, if only one number is included as an argument, it is the ______ value for the loop. Select one: a. stop b. start c. step d. You cannot just have one argument for a range function .
stop
17 In an "or" multiple conditional statement in order for the whole condition to return "True"... Select one: a. Any part of the "or" condition needs to be "True", but not all parts can be "True" b. The first part of the "or" condition must be "True" c. Any one part of the "or" condition needs to be "True" d. The last part of the "or" condition must be "True"
Any one part of the "or" condition needs to be "True"
10 In an if-elif-else statement the number of elif conditions allowed in one if-elif-else statement is? Select one: a. 7 b. As many as needed c. Based on what is declared in the program d. 1
As many as needed
25 What is the output if the user enter the numeric 12 for input of the following code? age = int(input('Enter age: ')) if age <= 1: print('Infant') else: if age > 1 and age <= 12: print('Child') else: if age >= 12 and age < 20: print('Teenager') else: print ('Adult') Select one: a. Child b. Teenager c. Child Teenager d. The program will crash because it is not valid code
Child
30 In a flowchart what symbol represents a decision structure? Select one: a. Triangle b. Rectangle c. Diamond d. Polygram
Diamond
11 a = 4 b = 7 c = 10 Based on the above variables what is the output of the following: ((a < b) or (a < c)) and (not(c > b) and (b < c)) Select one: a. False b. True c. c > b < c d. This is not valid code
False
18 What is the output of the following code ? num = 5 if (num == 2): print("Two") elif num > 3: print("Great") elif num == 5: print("Equal") Select one: a. Great Equal b. Great c. Equal d. Two
Great
5 This block of code allows a program to decide on a course of action based on whether a certain condition is true or false? Select one: a. Or Block b. If Block c. And Block d. Else Block
If Block
23 Looking at the following code what is happening in this code? Select one: A. It accepts 4 test scores for 3 students and outputs the average of the 12 scores. B. It accepts 3 test scores for each of 3 students and outputs the average for each student. C. It accepts 4 test scores for 2 students, then averages and outputs all the scores. D. It accepts one test score for each of 3 students and outputs the average of the 3 scores.
It accepts 3 test scores for each of 3 students and outputs the average for each student.
14 What are the values that the variable num contains through the iterations of the following loop? for num in range(-9, 5, -2): Select one: A. -9, -7, -5, -3, -1, 1, 3, 5 B. -9, -7, -5, -3, -1, 1, 3 C. -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4 D. It will not contain any numbers because the loop will never iterate
It will not contain any numbers because the loop will never iterate
12 A ________ controls how many times in succession an operation (or a sequence of operations) is performed and is used to reduce repetitive sequential code. Select one: a. Loop b. variable c. flag d. break .
Loop
13 In Python the following are considered __________ __________. >, >=, <, <=, == and != Select one: a. Boolean Expressions b. Logical Operators c. Relationship Operators d. AND, OR & NOT operators
Relationship Operators
21 With the code below. What is the output if the user enters in a numeric 5 for input? weight = 0.0 shippingCost = 0.0 weight = float(input('Enter the weight of the package: ')) if weight > 10: shippingCost = 4.75 elif weight > 6: shippingCost = 4.00 elif weight > 2: shippingCost = 3.00 else: shippingCost = 1.50 print ('Shipping charge: $', format(shippingCost, '.2f')) Select one: a. Shipping charge: 3.00 b. Shipping charge: $ 4.00 c. Shipping charge: $ 1.50 d. Shipping charge: $ 3.00
Shipping charge: $ 3.00
3 In using the range function in a for-loop which argument is required by the function? Select one: a. Start b. Stop c. Step d. The function can have no arguments .
Stop
19 What is the output of the following code? num1 = 5 if (num1 >= 2): print(num1) else: num2 = 8 print(num2) print(num2) Select one: a. 5 8 b. 5 c. 8 8 d. Syntax error
Syntax error
8 What code statement causes the loop to terminate from anywhere in the loop structure. Select one: a. default b. continue c. exit d. break .
break
24 This coded statement causes the current pass through the body of a loop to end(terminate) and program execution goes back to the beginning of the loop? Select one: a. current b. break c. continue d. leave
continue
21 What will be displayed after the following code is executed? count = 4 while count < 12: print("counting") count = count + 2 Select one: A. counting counting counting counting B. counting counting counting counting C. counting counting D. counting counting counting
counting counting counting counting
22 A Boolean ______ variable is a variable that signals when some condition exists in a program. When this variable is set to False it signals the condition does not exist and when set to True it signals the condition does exist. Select one: a. count b. flag c. choice d. prompt
flag
30 According to our textbook this type of loop is a count-controlled loop. A count-controlled loop iterates a specific number of times. Select one: a. for-loop b. while-loop c. infinite-loop d. stop-loop
for-loop
29 Based on the variable assignment statements: a = 5 b = 6 Which code below is valid code in Python? Select one: a. If (a = b): b. If (a =! b): c. if (a <> b): d. if (a == b):
if (a == b):
1 Which is the correct format of an IF statement (assuming the "temp" variable has been declared and assign a value)? Select one: a. If (temp < 40): Print("A little cold isn't it") Else: Print("Nice weather were having") b. if (temp < 40) print("A little cold isn't it") else print("Nice weather were having") c. if (temp < 40): print("A little cold isn't it") else: print("Nice weather were having") d. if (temp < 40): print("A little cold isn't it") else: print("Nice weather were having")
if (temp < 40): print("A little cold isn't it") else: print("Nice weather were having")