Set 2 Zybook COSC 1306, Set 1 Zybook COSC 1306
Type the operator to complete the desired expression. numDogs and numCats differ numDogs ____ numCats
!=
Type the operator to complete the desired expression. numDogs is either less than or greater than numCats numDogs ____ numCats
!=
Write the simplest expression that captures the desired comparison. The character 'G' exists in the string my_str
'G' in my_str
Fill in the missing Boolean operators. Either wage is greater than 10 or age is less than 18. Use "or". Use > and < (not >= and <=). Use parentheses around sub-expressions. if ____ :
(wage > 10) or (age < 18)
What is the final value of employee_bonus for each given value of num_sales? if num_sales == 0: employee_bonus = 0 elif num_sales == 1: employee_bonus = 2 elif num_sales == 2: employee_bonus = 5 else: employee_bonus = 10 num_sales is 0
0
x is a non-negative number less than 100. if: ________ # evaluated to true else: # evaluated to false
0 <= x < 100
Determine the final value of sale_bonus given the initial values specified below. if sales_type == 2: if sales_bonus < 5: sales_bonus = 10 else: sales_bonus = sales_bonus + 2 else: sales_bonus = sales_bonus + 1 sale_type = 1; sale_bonus = 0
1
What is the final value of num_items? bonus_val = 0 num_items = 1 if bonus_val > 10: num_items = num_items + 3
1
To teach precedence rules, these questions intentionally omit parentheses; good style would use parentheses to make order of evaluation explicit. Which operator is evaluated first? w + 3 > x - y * z A. + B. - C. > D. *
D. *
weight = Get next input If weight < 150: Put "Can ride." to output Else: Put "Can't ride." to output What input value causes both the if branch to execute (outputting "Can ride") and the else branch to execute (outputting "Can't ride")? A. 149 B. 150 C. 151 D. No such value
D. No such value
What is the final value of num_items? Write "Error" if the code results in an error. num_items = 3 if num_items = 10: num_items = num_items + 1
Error
What is the final value of employee_bonus for each given value of num_sales? if num_sales == 0: employee_bonus = 0 elif num_sales == 1: employee_bonus = 2 elif num_sales == 2: employee_bonus = 5 else: employee_bonus = 10 num_sales is 7
10
What is the final value of num_items? bonus_val = 5 if bonus_val < 12: num_items = 100 else: num_items = 200
100
What is the final value of bonus_val? bonus_val = 11 if bonus_val < 12: bonus_val = bonus_val + 2 else: bonus_val = bonus_val + 10
13
weight = Get next input If weight < 150: Put "Can ride." to output Else: Put "Can't ride." to output What is output when the input is 150? A. Can ride. Done. Can't ride. Done. B. Can ride. Can't ride. Done. C. Can't ride. Done.
150 < 150 is false, so the branch executes.
Determine the final value of numBoxes. num_boxes = 0 num_apples = 9 if num_apples < 10: if num_apples < 5: num_boxes = 1 else: num_boxes = 2 else if num_apples < 20: num_boxes = num_boxes + 1
2
What is the final value of num_items? bonus_val = 12 if bonus_val < 12: num_items = 100 else: num_items = 200
200
Determine the final value of numBoxes. num_boxes = 0 num_apples = 9 if num_apples < 10: num_boxes = 2 if num_apples < 20: num_boxes = num_boxes + 1
3
What is the final value of num_items? Write "Error" if the code results in an error. num_items = 3 if num_items > 10: num_items = num_items + 1
3
What is the final value of bonus_val? bonus_val = 11 if bonus_val < 12: bonus_val = bonus_val + 2 bonus_val = 3 * bonus_val else: bonus_val = bonus_val + 10
39
What is the final value of num_items? bonus_val = 19 num_items = 1 if bonus_val > 10: num_items = num_items + 3
4
What is the final value of num_items? Write "Error" if the code results in an error. num_items = 3 if num_items == 3: num_items = num_items + 1
4
What is the final value of employee_bonus for each given value of num_sales? if num_sales == 0: employee_bonus = 0 elif num_sales == 1: employee_bonus = 2 elif num_sales == 2: employee_bonus = 5 else: employee_bonus = 10 num_sales is 2
5
What is the final value of num_items? bonus_val = 15 num_items = 44 if bonus_val < 12: num_items = num_items + 3 else: num_items = num_items + 6 num_items = num_items + 1
51
Determine the final value of sale_bonus given the initial values specified below. if sales_type == 2: if sales_bonus < 5: sales_bonus = 10 else: sales_bonus = sales_bonus + 2 else: sales_bonus = sales_bonus + 1 sale_type = 2; sale_bonus = 7
9
Type the operator to complete the desired expression. centsLost is a negative number centsLost ____ 0
<
Type the operator to complete the desired expression. numDogs and numCats are the same numDogs ____ numCats
==
Type the operator to complete the desired expression. numDogs is 0 numDogs ____ 0
==
Type the operator to complete the desired expression. userChar is the character 'x'. userChar ____ 'x'
==
Type the operator to complete the desired expression. numDogs is greater than 10 numDogs ____ 10
>
Which expression checks if the value 10 exists in the dictionary my_dict? A. 10 in my_dict['key'] B. 10 in my_dict C. None of the above
C. None of the above
Indicate whether the expression evaluates to true or false. x is 5, y is 7. Is x <> y a valid expression?
No
Indicate whether the expression evaluates to true or false. x is 5, y is 7. Is x =< y a valid expression?
No
Type the operator to complete the desired expression. numCars is 5 or greater numCars ____ 5
>=
Type the operator to complete the desired expression. numCars is greater than or equal to 5 numCars ____ 5
>=
Click the expression that is False. A. 'FRIDAY' == 'friday' B. '1' < '2' C. 'a' != 'b' < 'c'
A. 'FRIDAY' == 'friday'
Which illustrates the actual order of evaluation via parentheses? (num1 == 9) or (num2 == 0) and (num3 == 0) A. (num1 == 9) or ((num2 == 0) and (num3 == 0)) B. ((num1 == 9) or (num2 == 0)) and (num3 == 0) C. (num1 ==9) or (num2 == (0 and num3) == 0)
A. (num1 == 9) or ((num2 == 0) and (num3 == 0))
price = 155 age = Get next input If age > 60: price = price - 20 Put "Cost: " to output Put price to output If the input is 80, the output is Cost: _____ . A. 135 B. 155
A. 135
price = 155 age = Get next input If age > 60: price = price - 20 Put "Cost: " to output Put price to output If the input is 25, the output is Cost: _____ . A. 135 B. 155
A. 155
weight = Get next input If weight < 150: Put "Can ride." to output Else: Put "Can't ride." to output What is output when the input is 90? A. Can ride. Done. B. Can't ride. Done.
A. Can ride. Done.
x = Get next input y = Get next input If x > y: max = x Else: max = y When the input is -3 0, which branch executes? A. If B. Else
A. Else
x = Get next input y = Get next input If x > y: max = x Else: max = y When the input is 99 98, which branch executes? A. If B. Else
A. If
Which comparison will compile AND consistently yield expected results? Variables have types denoted by their names. my_int == 42 A. OK B. Not OK
A. OK
Which comparison will compile AND consistently yield expected results? Variables have types denoted by their names. my_string == 'Hello' A. OK B. Not OK
A. OK
Given num_people = 10, num_cars = 2, user_key = 'q'. (num_people >= 20) or (num_cars > 1) A. True B. False
A. True
Given num_people = 10, num_cars = 2, user_key = 'q'. (user_key == 'x') or ((num_people > 5) and (num_cars > 1)) A. True B. False
A. True
Given num_people = 10, num_cars = 2, user_key = 'q'. not (user_key == 'a') A. True B. False
A. True
Given num_people = 10, num_cars = 2, user_key = 'q'. num_people >= 10 A. True B. False
A. True
Given num_people = 10, num_cars = 2, user_key = 'q'. user_key != 'a' A. True B. False
A. True
not x == 3 evaluates as not (x == 3)? A. Yes B. No
A. Yes
val = Get next input If val < 0: val = -val If the input is -6, does the branch execute? A. Yes B. No
A. Yes
w + x == y + z evaluates as (w + x) == (y + z)? A. Yes B. No
A. Yes
If party of 1: counter Else if party of 2: a small table Else: a large table A party of 5 is sat at _____ . A. a large table B. nowhere
A. a large table
If party of 1: counter Else if party of 2: a small table Else: a large table A party of 1 is sat at _____ . A. the counter B. a small table
A. the counter
Consider the if-else if-else structure below: If x equals -1 Put "Disagrees" to output Else If x equals 0 Put "Neutral" to output Else If x equals 1 Put "Agrees" to output Else Put "Invalid entry" to output In the code above, suppose a programmer, after the third branch (x equals 1), inserts a new branch: Else If x equals -1 ... When might that new branch execute? A. When x is -1 B. When x is 1 C. Never
C. Never
Consider the if-else if-else structure below: If x equals -1 Put "Disagrees" to output Else If x equals 0 Put "Neutral" to output Else If x equals 1 Put "Agrees" to output Else Put "Invalid entry" to output If x is 1, what is output? A. Disagrees B. Neutral C. Agrees D. Invalid entry
C. Agrees
weight = Get next input If weight < 150: Put "Can ride." to output Else: Put "Can't ride." to output What value causes "Done." to NOT be output? A. 130 B. 160 C. No such value
C. No such value
Determine the final value of sale_bonus given the initial values specified below. if sales_type == 2: if sales_bonus < 5: sales_bonus = 10 else: sales_bonus = sales_bonus + 2 else: sales_bonus = sales_bonus + 1 sale_type = 2; sale_bonus = 4
10
Click the expression that is True. A. {'Henrik': '$25'} == {'Daniel': '$25'} B. (1, 2, 3) > (0, 2, 3) C. [1, 2, 3] >= ['1', '2', '3']
B. (1, 2, 3) > (0, 2, 3)
Which illustrates the actual order of evaluation via parentheses? not (bats < birds) or (birds < insects) A. not ((bats < birds) or (birds < insects) B. (not (bats < birds)) or (birds < insects) C. ((not bats) < birds) or (birds < insects)
B. (not (bats < birds)) or (birds < insects)
Which expression checks whether the list my_list contains the value 15? A. 15 in my_list[0] B. 15 in my_list C. my_list['15'] != 0
B. 15 in my_list
weight = Get next input If weight < 150: Put "Can ride." to output Else: Put "Can't ride." to output What is output when the input is 200? A. Can ride. Done. B. Can't ride. Done.
B. Can't ride. Done.
Given num_people = 10, num_cars = 2, user_key = 'q'. (num_people >= 10) and (num_cars > 2) A. True B. False
B. False
Given num_people = 10, num_cars = 2, user_key = 'q'. not ((num_people >= 10) and (num_cars > 2)) A. True B. False
B. False
Given num_people = 10, num_cars = 2, user_key = 'q'. not (num_cars < 5) A. True B. False
B. False
To teach precedence rules, these questions intentionally omit parentheses; good style would use parentheses to make order of evaluation explicit. To what does this expression evaluate, given x = 4, y = 7. x == 3 or x + 1 > y A. True B. False
B. False
Consider the if-else if-else structure below: If x equals -1 Put "Disagrees" to output Else If x equals 0 Put "Neutral" to output Else If x equals 1 Put "Agrees" to output Else Put "Invalid entry" to output If x is -2, what is output? A. Disagrees B. Invalid entry C. (Nothing is output)
B. Invalid entry
price = 155 age = Get next input If age > 60: price = price - 20 Put "Cost: " to output Put price to output If the input is 60, will the branch be taken? A. Yes B. No
B. No
val = Get next input If val < 0: val = -val If the input is 0, does the branch execute? A. Yes B. No
B. No
w and x == y and z evaluates as (w and x) == (y and z)? A. Yes B. No
B. No
Consider the if-else if-else structure below: If x equals -1 Put "Disagrees" to output Else If x equals 0 Put "Neutral" to output Else If x equals 1 Put "Agrees" to output Else Put "Invalid entry" to output In the code above, suppose a programmer removed the Else part entirely. If x is 2, which is correct? A. The last branch, meaning the Else If x equals 1 branch, will execute. B. No branch will execute. C. The program is not legal.
B. No branch will execute.
Which comparison will compile AND consistently yield expected results? Variables have types denoted by their names. my_double == 3.25 A. OK B. Not OK
B. Not OK
Consider the if-else if-else structure below: If x equals -1 Put "Disagrees" to output Else If x equals 0 Put "Neutral" to output Else If x equals 1 Put "Agrees" to output Else Put "Invalid entry" to output Could the programmer have written the three branches in the order x equals 1, x equals 0, and x equals -1, and achieved the same results? A. No B. Yes
B. Yes
If party of 1: counter Else if party of 2: a small table Else: a large table A party of 2 is sat at _____ . A. the counter B. a small table
B. a small table
To teach precedence rules, these questions intentionally omit parentheses; good style would use parentheses to make order of evaluation explicit. Which operator is evaluated first? not y and x A. and B. not
B. not
Which illustrates the actual order of evaluation via parentheses? not green == red A. (not green) == red B. not (green == red) C. (not green =)= red
B. not (green == red)
x = Get next input y = Get next input If x > y: max = x Else: max = y If the inputs are 5 5, does max get assigned with x or y? A. x B. y
B. y
x = Get next input y = Get next input If x > y: max = x Else: max = y The if branch assigns max = x. The else branch assigns max = ? A. x B. y
B. y
Click the expression that is False. A. 5 <= 5.0 B. 10 != 9.999999 C. (4 + 1) != 5.0
C. (4 + 1) != 5.0
Which illustrates the actual order of evaluation via parentheses? bats < birds or birds < insects A. ((bats < birds) or birds) < insects B. bats < (birds or birds) < insects C. (bats < birds) or (birds < insects)
C. (bats < birds) or (birds < insects)
To teach precedence rules, these questions intentionally omit parentheses; good style would use parentheses to make order of evaluation explicit. In what order are the operators evaluated? w + 3 != y - 1 and x A. +, !=, -, and B. +, -, and, != C. +, -, !=, and
C. +, -, !=, and
Indicate whether the expression evaluates to true or false. x is 5, y is 7. x == y
False
Indicate whether the expression evaluates to true or false. x is 5, y is 7. y != 7
False
Indicate whether the expression evaluates to true or false. x is 5, y is 7. x != y
True
Indicate whether the expression evaluates to true or false. x is 5, y is 7. x <= 7
True
Indicate whether the expression evaluates to true or false. x is 5, y is 7. x == 5
True
Indicate whether the expression evaluates to true or false. x is 5, y is 7. y != 99
True
Indicate whether the expression evaluates to true or false. x is 5, y is 7. y >= 7
True
Fill in the missing Boolean operators. days is greater than 30 and less than 90. if (days > 30) ____ (days < 90):
and
Fill in the missing Boolean operators. max_cars is between 0 and 100. if (max_cars > 0) ____ (max_cars < 100):
and
Fill in the missing Boolean operators. num is a 3-digit positive integer, such as 100, 989, or 523, but not 55, 1000, or -4. For most direct readability, your expression should compare directly with the smallest and largest 3-digit number. if (num >= 100) ____ :
and (num <= 999) or and (num < 1000) or and num <= 999 or and num < 1000
Fill in the missing Boolean operators. num_dogs is 3 or more and num_cats is 3 or more. if (num_dogs >= 3) ____ :
and (num_cats >= 3) or and (num_cats > 2) or and num_cats >= 3 or and num_cats > 2
If num_people is greater than 10, execute group_size = 2 * group_size. Otherwise, execute group_size = 3 * group_size and num_people = num_people - 1.
if num_people > 10: group_size = 2 * group_size else: group_size = 3 * group_size num_people = num_people - 1
If num_players is greater than 11, execute team_size = 11. Otherwise, execute team_size = num_players. Then, no matter the value of num_players, execute team_size = 2 * team_size.
if num_players > 11: team_size = 11 else: team_size = num_players team_size = 2 * team_size
If user_age is greater than 62, assign item_discount with 15. Else, assign item_discount with 0.
if user_age > 62: item_discount = 15 else: item_discount = 0
Write the simplest expression that captures the desired comparison. my_str is not the third element in the list my_list
my_str is not my_list[2]
Fill in the missing Boolean operators. num_stores is between 10 and 20, inclusive. if (num_stores >= 10) and ( ____ ):
num_stores <= 20 or num_stores < 21
Write the simplest expression that captures the desired comparison. x is a key in the dict my_dict
x in my_dict
Write the simplest expression that captures the desired comparison. The variables x and y are unique objects.
x is not y or y is not x
Write a relational expression using operator chaining. x is less than y but greater than z
z < x < y