CSC241 Final

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which expression is equivalent to: not x and y == a and b? ((not x) and y) and (a and b) ((not x) and (y == a)) and b (not (x and y)) == (a and b) not ((x and (y == a)) and b)

((not x) and (y == a)) and b

What sequence is generated by range(4)? 0 1 2 3 4 4 1 2 3 4 0 1 2 3

0 1 2 3 4

What is the value of x after the following code is executed? x = 17 if x * 2 <= 34: x = 0 else: x = x + 1 x = x + 1 18 35 19 1

1

What sequence is generated by range(1,4)? 0 1 2 3 4 4 1 2 3 1 2 3 4

1 2 3

What sequence is generated by range(1, 10, 3) 1 4 7 10 1 11 21 1 3 6 9 1 4 7

1 4 7

What sequence is generated by range(1, 8, 3) 1 4 7 1 5 8 1 4 7 10 0 3 6 9

1 4 7

What is output? def calc(num1, num2): return 1 + num1 + num2 print(calc(4, 5), calc(1, 2)) 9 3 10 4 4, 5, 1, 2 145 112

10 4

What values for x cause Branch 1 to execute? If x > 100 : Branch 1 Else If x > 200: Branch 2 100 to 200 101 or larger 100 or larger 101 to 200

101 or larger

What is the value of test_val after the following code is executed? a = 12 test_val = 6 if a * 2 == test_val: a = a + 7 else: test_val = 2 * a

13

What is x's final value? x = 10 y = 20 if y <= 2 * x x = x + 5 else: x = x * 2 25 10 15 20

15

What is the final value of z? grades = { 'A': 90, 'B': 80, 'C': 70, 'D': 60 } my_grade = 70 if my_grade not in grades: z = 1 else:z = 2 if 'F' in grades: z = z + 10 else:z = z + 20 21 12 22 11

21

What is the value of x after the following code is executed? x = 7 If x < 7 x = x + 1 x = x + 2 10 8 9 7

9

Which of the following is true? A function can have any number of return statements, or no return statement at all. A function must always have at least one return statement. A function must have exactly one return statement, or no return statement at all. A function can only return strings and numbers, not lists or dictionaries.

A function can have any number of return statements, or no return statement at all.

For what values of x will "Medium" be output? If x > 40: Output "Large" Else If x > 20: Output "Medium" Else If x > 10: Output "Small"

Any x from 21 to 40

Which of the following loops is best implemented with a while loop? Checking to see if a list of integers contains the value 12. Asking the user to enter positive integers, exiting by entering -1. Looping through the characters in a string, and displaying 'yes' if it contains a vowel. Counting how many keys in a dictionary start with the letter 'A'.

Asking the user to enter positive integers, exiting by entering -1.

Question 17 With the logic block shown below, what is output when grade is assigned with the value 75? If grade < 50Put "F" to output Else If grade < 60 Put "D" to output Else If grade < 75 Put "C" to output Else If grade < 85 Put "B" to output Else If grade <= 100 Put "A" to output ElsePut "Invalid grade" to output

B

Which of the following loops is best implemented with a for loop? Asking a user to enter names until the user enters 'Quit'. Starting from a user-entered integer, increment the value until the value is a prime number. Reading values from a temperature sensor until it gives a value greater than 100 degrees. Counting the number of negative values in a list of integers. Question 510 / 10 points

Counting the number of negative values in a list of integers.

For what values of integer x will Branch 3 execute? If x < 10 : Branch 1 Else If x > 9: Branch 2 Else: Branch 3 Values between 9 and 10 Value 10 only For no values (never executes) Value 10 or larger

For no values (never executes)

After the program runs, what is the value of y? def print_sum(num1, num2) print(num1 + num2) y = print_sum(4, 5) None 4 5 45 9

None

Which line in the function print_greeting() must be changed if the user wishes to print the greeting three times with three different names? def print_greeting(name): print('Welcome message:') print('Greetings', name) None. To print the greeting with three different names, the main program must call print_greeting() three times with three different arguments. def print_greeting() print('Welcome message:') print('Greetings', name)

None. To print the greeting with three different names, the main program must call print_greeting() three times with three different arguments.

What is the output? names = ['Bob', 'Jill', 'Xu'] ages = [24, 18, 33] for index in [2, 0, 1]: print(names[index] + ":" + str(ages[index])) Xu:24Bob:18Jill:33 Xu:33Bob:24Jill:18 Bob:24Jill:18Xu:33 Xu, Bob, Jill:33, 24, 18

Xu:33 Bob:24 Jill:18

Which correctly calls the add() function? def add(a, b, c): return a + b + c add(2; 4; 6) add(2 + 4 + 6) add(2, 4, 6) add(2 4 6)

add(2, 4, 6)

In the following code, the variable val is the function call's _____. def calc_square_area(size): area = size * sizereturn area val = float(input('Enter size of square: ')) square_area = calc_square_area(val) print("A square of size", val, "has area", square_area)

argument

Which statement removes entry "1G1JB6EH1E4159506" from the dictionary cars_dict? delete(cars_dict["1G1JB6EH1E4159506"]) cars_dict{"1G1JB6EH1E4159506"}.del() cars_dict["1G1JB6EH1E4159506"] = None del cars_dict["1G1JB6EH1E4159506"]

del cars_dict["1G1JB6EH1E4159506"]

Which data type is the correct choice to store the number of wins associated with each basketball team in the NBA? float string tuple dict

dict

Which statement changes the value associated with key "Lemon" to 0.75 in the dictionary fruits_dict? fruits_dict["Lemon"] = 0.75 dict("Lemon") = fruits_dict[0.75] fruits_dict[0.75] = "Lemon" fruits_dict[Lemon] = 0.75

fruits_dict["Lemon"] = 0.75

After a function's last statement is executed, the program returns to the next line after the _____. import statement function call function definition start of the program

function call

The following program prints the number of integers in my_list that are greater than the previous integer in the list. Which choice fills in the blank to complete the for loop? my_list = [3, 2, 7, 8, 6, 9]count = 0for ____: if my_list[i] > my_list[i-1]: count = count + 1print(count) i in range(1, len(my_list)) i in range(0, len(my_list)+1) i in range(0, len(my_list)) i in range(1, len(my_list)+1)

i in range(1, len(my_list))

A child is required to use a booster seat in a car until the child is 9 years old, unless the child reaches the height of 59 inches before age 9. Which expression can be used to decide if a child requires a car seat or not? if age < 9 or height < 59: if age >= 9 or height >= 59: if age >= 9 and height >= 59: if age <= 9 and height <=59:

if age >= 9 or height >= 59:

A company wants to send a reminder email to users who have not logged in for more than 10 days, but less than 20 days. Which expression can be used to decide if a user should get an email or not? if days_since_login > 10 or days_since_login < 20: if days_since_login > 10: if days_since_login > 10 and not days_since_login < 20: if days_since_login > 10 and days_since_login < 20:

if days_since_login > 10 and days_since_login < 20:

Which determines if user_unit is in the list accepted_units?accepted_units = [ 'in', 'cm', 'mm', 'km', 'miles' ] if accepted_units in user_unit: if user_unit == x in accepted_units: if user_unit in accepted_units: if user_unit == (accepted_units):

if user_unit in accepted_units:

What condition should replace ZZZ to output "Same name" only if the values of two variables are the same? my_name = input("Enter my name: ") your_name = input("Enter your name: ") if ZZZ: print("Same name") 1.my_name is your_name 2.id(my_name) == id(your_name) 3.my_name = your_name 4.my_name == your_name 5.Question 11

my_name == your_name

In the following code, the variable size is the function's _____. def calc_square_area(size): area = size * size return area val = float(input('Enter size of square: ')) square_area = calc_square_area(val) print('A square of size', val, 'has area', square_area) argument property parameter value

parameter

The variable emails_dict is assigned with a dictionary that associates student ids with email addresses. Which statement prints the email address associated with the student id "C2104"? 1.print(value of emails_dict("C2104")) 2.print(emails_dict["[email protected]"]) 3.print(key of emails_dict("C2104")) 4.print(emails_dict["C2104"])

print(emails_dict["C2104"])

Which XXX causes the program to output the message "Hello!"? def print_message(): print('Hello!') XXX print_message() print_message print_message('Hello!') def print_message()

print_message()

Which range() function call generates every even number between 20 and 30 (including both 20 and 30)? range(20, 30, 1) range(20, 30, 2) range(20, 31, 2) range(30, 20, 2)

range(20, 31, 2)

Fill in the blank so that the output is a count of how many negative values are in temperatures? temperatures = [-2, 8, 4, -7, 18, 3, -1]count = 0for t in temperatures: if _____: count = count + 1print("Total negative temperatures:", count)

t < 0

Which expression for YYY will result in an output of "Pass" only if x is exactly 32? if YYY:print('Pass')else:print('Fail') x != 32 x == 32 x >= 32 x <= 32

x == 32

Which XXX is valid for the following code? def calc_sum(a, b):return a + b XXXprint(y) calc_sum(y, 4, 5) y = calc_sum(4 + 5) y = calc_sum(4, 5) y = calc_sum()

y = calc_sum(4, 5)

If x = 10 and y = 20, which expression is True? x == y y >= x y != 2 * x y <= x

y >= x


Conjuntos de estudio relacionados

Anatomy & Physiology Lecture - Chapter 8

View Set

Chapter 5: Introduction to Risk, Return, and the Historical Record (Review Questions)

View Set

NMNC 1110 EAQ 7: Fluid and Electrolytes

View Set

Financial Sector Regulation Exam 1

View Set