CICS 110

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What conditions have to be true to make the following code display "F"? if color == 'red': if style < 3: print('D') elif style <= 5: print('E') else: print('F') elif color == 'blue': Print('D') A) there is no way to get this print out B) color is 'red' and style is 4 C) color is 'red' and style is 5 D) this print out will occur regardless of input E) color is 'blue' and style is 3 F) color is 'red' and style is 6

F) color is 'red' and style is 6

In computer science terminology, objects like integers and strings that can't be modified are called ____. A) constant B) unchangeable C) mutable D) static E) frozen F) immutable G) stuck

F) immutable

All errors are equal to the Python debugger, and will be about the same level difficulty to fix True or False?

False

Consider the following code: if (first_number > 10) and (second_number <=7): first_number = first_number + 1 else: first_number = first_number - 1 Assuming first_number is 19 and second_num is 6, what is the value of the first_number after running this code?

20

The code that includes the keyword "def" is called a ______ A) function reference B) function call C) function constructor D) function definition

D) function definition

Match Str, float, int A collection of characters - Positive or negative numbers with a decimal point - Positive or negative number with no decimal point -

A collection of characters - str Positive or negative numbers with a decimal point - float Positive or negative number with no decimal point - int

Which of the following is a valid name for a variable in Python? A) false B) while C) Friendly's D) 1_counter E) my-excavator

A) false

To continue, a user types 'c'. To quit, a user types any other key. Which expression evaluates to true if a user should quit? Assume this line has already occurred: key = input("Please type c to continue") A) key != 'c' B) key == 'c' C) None of these D) (!key) == 'c' E) key == (!'c')

A) key != 'c'

_____ are the decisions/processes the code will make with objects A) logic B) code C) variables D) steps

A) logic

Which of the following is a Python operator used to compute power/exponentiation, such as 2^4? A) math.power() B) ** C) math.log() D) // E) ^ F) %

B) **

Which statement is true regarding the pop() method for lists (when no values are provided in the ()? A) pop() removes the last item added to the list, and returns it B) there is no pop method for lists C) pop() returns but doesn't remove a random item in there list D) pop() removes the first item added to the list, and returns it E) pop() removes a random item in the list, and returns it

A) pop() removes the last item added to the list, and returns it

Which of the following can create the integer sequence 1, 3, 5, 7, 9? A) range(1, 10, 2) B) range(1, 10) C) range(1, 9) D) range(1, 9, 2) E) range(0, 11, 2)

A) range(1, 10, 2)

After the program runs, what is the value of y? def increment(y): y = y + 1 increment(1) print(y) A) this will throw an error before it can finish B) 2 C) None D) 1 E) 0

A) this will throw an error before it can finish

Which of the following is a reason to use functions?

A) to reduce memory usage B) to make code run faster C) to break a problem up into smaller pieces D) all of these

How many iterations does the following while loop run? x = 8 while x > 1: x/= 2 print('All done') A) 8 B) 3 C) the loop never ends D) 2 E) 7 F) 4

B) 3

Match the given value to what value python would create if casted as a bool() True or False "True" = "False" = 2-4 = " " = 0.0 = 4-2*2 = 18.59 =

"True" = True "False" = True 2-4 = True " " = False 0.0 = False 4-2*2 = False 18.59 = True

Match the following statements to the value True or False A function must have exactly one return statement m, or no return statement at all = A function must always have at least one return statement = A function can have any number of return statements, or no return statement at all = A function will only ever run when it is called, and never run when it is defined = A function can only return strings and numbers, not lists or tuples = A variable created inside a function works exactly the same way as a variable created outside a function = A function could only be defined inside another function =

A function must have exactly one return statement m, or no return statement at all = false A function must always have at least one return statement = false A function can have any number of return statements, or no return statement at all = true A function will only ever run when it is called, and never run when it is defined = true A function can only return strings and numbers, not lists or tuples = false A variable created inside a function works exactly the same way as a variable created outside a function = false A function could only be defined inside another function = true

Which of the following expressions causes an implicit conversion between types? Assume variable x is an integer, t is a float, and name is a string A) 7.5 + (x/2) B) print(str(t)) C) "Hello, " + str(name) D) x + 2 * x E) None of these

A) 7.5 + (x/2)

What's the range of values for the variable grade that can result in the following code below printing out 'B'? if grade >= 70: print('C') elif grade >= 80: print('B') elif grade >= 90: print('A') A) It will never print out 'B' B) greater than or equal to 70, but less than 80 C) greater than or equal to 80, but less than 90 D) greater than or equal to 70 E) greater than or equal to 80

A) It will never print out 'B'

Which of the following is true? A) a function's parameter must be variables — they may not be expressions B) a function must have at least one parameter in its definition A function must have at least one return statement in the function body D) a function can only return strings and numbers, and may not return other types of objects E) when calling a function, the arguments passed to the function must be variables — they may not be expressions

A) a function's parameter must be variables — they may not be expressions

What is the difference between a syntax error, and logic error? A) a syntax error violates the rules of python, while a logic error is correct python code but it doesn't behave as intended B) Syntax error are just visual, and don't impact the code, while a logic error stops things from running C) There is no difference, an error is an error D) a syntax error is found before the code can start running, a logic error stops the program while code is running E) a syntax error is found when you are running the code, while a logic error is caught before the program starts running

A) a syntax error violates the rules of python, while a logic error is correct python code but it doesn't behave as intended

Which one of the following expressions is a correct way to check if an integer A is divisible by 4 (I.e. a multiple of 4)? The expression should return True if A is divisible by 4 and False otherwise. A) A / 4 == 0 B) A / 4 == A // 4 C) int(A / 4) == A // 4 D) A % 4 != 0 E) A // 4 == 0

B) A / 4 == A // 4

Identify the error in the following function implementation. The function weave (a,m,b,n) should take in two strings a and b, two ints n and m. It should then interweave m copies of the string a with n copies of the string b and return the result 1| def weave (a,m, b,n) : 2| least = min (m, n) 3| result = least*(a+b) + (least-m*a + (least-n*b 4| print(result) 5| print (weave( 'on' ,2, '1', 1)) A) There is no error in this function. B) The function needs to return the generated value, not print it out, in line 4 C) The logic of the function is wrong, they are not creating the correct string in the variable result (lines 2-3). D) The code is relying on functions that haven't been created, like the min() function in line 2. E) The types of the parameters and the return type are not specified in the function header in line 1 F) In line 3 there is a type error, they are either multiply, subtracting, or adding incompatible types (like subtracting a str from a str)

B) The function needs to return the generated value, not print it out, in line 4

fruits = ['apple', 'banana", 'orange', 'pear'] what would the list become after running. fruits.insert(1, fruits.pop(3)) A) ['pear', 'banana", 'orange', 'apple'] B) ['apple', 'pear", 'banana ', 'orange'] C) ['apple', 'pear", 'orange', 'banana '] D) ['pear', 'apple", 'banana ', 'orange'] E) ['apple', 'orange", 'pear', 'banana '] F) it leads to an index-out-of-range error

B) ['apple', 'pear", 'banana ', 'orange']

Which of the following are not built-in functions talked about in class or in zybook? A) type() B) mean() C) max() D) len() E) abs()

B) mean()

Which statement removes the last element of my_list defined below (multiple answers possible): my_list = ['Wow', True, 419] A) none of these B) my_list.pop(len(my_list)-1) C) my_list.remove(len(my_list)-1) D) my_list.pop(3) E) my_list.pop(len(my_list)) F) my_list.remove()

B) my_list.pop(len(my_list)-1)

Which of the following is not a part of the computer model we discussed in class? A) memory B) power supply C) processor D) input E) output

B) power supply

Choose the print statement that generates ['a', 'b', 'c', 'd', 'e', 'f'] as the output for my_list = ['a', 'b', 'c', 'd', 'e','f','g'] A) print(my_list[0:5]) B) print(my_list[0:-1] C) print(my_list[1:-2:2]) D) none of these E) print(my_list[-1:0])

B) print(my_list[0:-1]

Select every statement that is valid Python code, meaning code doesn't violate any of the rules of Python we have talked about. A) import = "Math" B) 4 = x C) Def = "function" D) x + 5 = 10 E) 8 ** (3 + 5) F) 10variable = 10 G) name = " 'Luigi' "

C) Def = "function" G) name = " 'Luigi' "

What does the following code print out? Def func(n): n **= 2 x = 3 print(func(x)) A) 8 B) 3 C) none D) 9 E) 6

C) none

Which expression below is a correct implementation of the condition "x and y are NOT another larger than 50" (I.e. it returns True if x and y are NOT another larger than 50, and False otherwise)? A) (x>50 and y<=50) or (x<=50 and y>50) B) not (x>50 or y>50) C) x<=50 or y<=50 D) not (x<=50 and y<=50) E) x<=50 and y<=50

C) x<=50 or y<=50

Which of the following is the correct line that could replace XXX for this to be valid (error free) code? Def calc_sum(a, b): return a + b XXX print(y) A) y = calc_sum(4 + 5) B) y = calc_sum() C) y = calc_sum(4, 5) D) calc_sum(y, 4, 5)

C) y = calc_sum(4, 5)

Excess indentation must be removed from which lines to make code correct? 1. print('start') 2. if 20 > 10: 3. print('large') 4. else: 5. print('small') 6. print('done') A) 1, 6 B) 2, 4, 6 C) indentation doesn't matter D) 2, 3, 4 E) this indentation is fine as it is F) 1, 2, 3

D) 2, 3, 4

What does the following program print out? x = 1 while True: if x > 5: break elif x == 4: continue else: x += 2 print(x) A) 4 B) 6 C) the loop never ends D) 5 E) 7

D) 7

Which of the following statements is true about a function in Python? A) a function may not call another function in its body B) a function must have at least one return statement C) when calling a function, the arguments passed to the function must be variables — they may not be expressions D) a function's parameter must be variables — they may not be expressions

D) a function's parameter must be variables — they may not be expressions

Which of the following statements removes the value 'Google' from the list, companies? companies = ['Apple', 'Microsoft', 'Google', 'Amazon'] A) companies.pop('Google') B) multiple answers are correct C) companies.pop(3) D) companies.remove('Google') E) no answers are correct F) companies.remove(2)

D) companies.remove('Google')

Which of the following is true about a list object in Python? A) it is defined using a pair of curly brackets B) It must contain at least one element C) it is immutable D) it may contain another list E) all elements in a list must be of the same data type

D) it may contain another list

Which statement correctly explains a difference between lists and tuples? A) list are created using parentheses (), while tuples are made with brackets [ ] B) there is no difference between a list and a tuple in Python. C) list items can be accessed by indexing and slicing, but tuple items cannot be sliced D) none are correct E)) tuples are like strings but for integers, while lists are like strings but for any data F) lists can hold any amount of items but tuples can only hold two items

D) none are correct

If a variable age stores a person's age as an integer, and a variable height stores their height in centimeters; which of the following expressions returns true only when someone is between 13 and 19, and they are 195cm? A) age >=13 and age >=19) and (height == 195) B) age >=13 or age <=19) and (height == 195) C) None of these will work. D) not(age < 13 or age >19) and (height == 195) E) age >=13 or age <=19) or (height == 195)

D) not(age < 13 or age >19) and (height == 195)

Identify the error with the code written below. The program is supposed to ask the user for two numbers, then output the subtraction of the two numbers. A) the data types of the two variables num1 and num2 must be declared first B) print() can only print out strings, not numbers C) the input() function cannot take parameters inside its parentheses D) num1 and num2 are both strings, subtracting two strings is invalid E) if one number is an integer and the other is a float, you cannot subtract them

D) num1 and num2 are both strings, subtracting two strings is invalid

What is the result (in terms of data type and value) of the following expression? "23" + '45' A) integer 68 B) integer 2345 C) the expression results in an error D) string '2345' E) float 68.0 F) string '68'

D) string '2345'

What is the value of the list, after the operations are done: B_list = [4, 5, 6] B_list.pop(1) B_list.remove(5) B_list.append(7) B_list.insert(0, '3') B_list.pop() A) [ ] B) ['3', 4] C) ['3', 4, 5, 6, 7] D) you get an error before it can complete E) [7, '3', 4, 5, 6]

D) you get an error before it can complete

What is the result if the expression: int('175.0')? A) there is no way to know B) the value 1750 as an int C) the value '1750' as a string D) the value 175.0 as a float E) an error: the string doesn't represent an integer value

E) an error: the string doesn't represent an integer value

In Python, if you call the type() function on an object, what does it return? A) the time stamp that the object was created B) the value of the object C) the size (number of bytes) of the object in memory D) the unique identifier representing the objects memory address E) the data type of the object

E) the data type of the object

If alist = [0, 1, 2, 3, 4, 5], write down the value of alist[len(alist)//3]. Write 'error' if an index is out of range error.

Len(alist) = 6, 6//3 = 2, answer = 2

For each data type listed below, select if it's mutable or immutable Mutable Immutable List - Str - Tupple - Float - Int - Bool -

List - mutable Str - immutable Tupple - immutable Float - immutable Int - immutable Bool - immutable

Consider the following 2 lines of code. What is the output? Type 'error' if an error would be thrown. Type 'none' if nothing would be output. w_str = "Welcome" print(w_str[5])

M

Write a function, named sum_of_11st, that calculates and returns the sum of all numbers in a list whose values are between [a,b]. Specifically, the function should: • Take 3 parameters: the first is a list of numbers, the second and third are two numbers a and b. You can assume acab. • Iterate over every number in the list, and sum up all numbers whose values are between [a, bj, inclusive on both ends. Return the result of the sum. • Your code must be indented correctly. • You will receive partial credit if your solution is partially correct but not completely correct. For example, calling sum _of_list((1, 8, 4, 7, 5, 2], 3, 5) should return 9.

Reference solution : def sum_of_list(list, a, b): sum = 0 for n in list: if a<=n<=b: sum += n return sum

In Python casting an object into a new data type doesn't change the underlying object at all, instead, it creates a new object either the desired data type. True False

True

In Python these two expressions will result in the same number: 1*2+3*4 (1*2)+(3*4) True False

True

For each of expressions below, select whether it evaluates to True or False bool('False') - 1.0 == '1.0' - '1' + '2' == '3' - (1 == 2) == False - 1 == (2 == False) -

bool('False') - True 1.0 == '1.0' - False '1' + '2' == '3' - False (1 == 2) == False - True 1 == (2 == False) - False

How can you create a string from an integer in python? a) You can't create a string from an integer b) convert(string, int) c) str() d) int() e) string_to_int() f) string()

c) str()


Kaugnay na mga set ng pag-aaral

General Chemistry UWORLD Atoms and molecules

View Set

Pediatrics Hematology and Oncology Exam Review

View Set

Chapter 44: Nursing Management: Patients With Oncologic Disorders of the Brain and Spinal Cord

View Set

MARK3336 Ch. 3 Video: Apple Unveils the Latest Apple Watch

View Set

NCLEX questions-Positioning Clients

View Set