COSC 130 FINAL QUESTIONS

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Assuming abc_str = "abcdefg", what substring does abc_str[4:] return?

"efg"

What is the proper way to turn a list of strings ['a' , 'b', 'c' ] back into a single string '1 2 3'?

' '.join(['a','b','c'])

Select all expressions that result in an Error

'2' == 2 1 < 5 / 0

Select all expressions that evaluate to False

(1 < 1) or ( 0 >= 1) (1 < 2) and (2 < 1) 1 != 1 not True

What is the technical term for the electronic "switch" inside the modern computers?

(T|t)ransistor(s|)

Select all options that are python punctuators/delimiters?

) ( : , (comma)

Which of the following is a repetition operator?

*

Select all options that are python operators

+ * // / (forward slash)

What is the difference between the / and the // operator?

/ - divides resulting in a fraction(float) // - results in only the quotient, remainder

How much dirt is there in a hole that measures two feet by three feet by four feet?

0

What is the output of the following code? temp = 0temp += 7 temp = 2 temp -= 2 print(temp)

0

What is the output of this while loop? a = 0 while a < 4 : print(a) a = a + 1

0 1 2 3

Assuming my_str = "Abc", what does my_str.upper().find("B") return?

1

Assuming the following function definition, def fun_one(my_int1, my_int2 = 0, my_int3=1): return my_int1 ** 2 * my_int2 + my_int3 what value is returned when the function call: fun_one(5) is made?

1

Assuming the following list declaration: my_list = ["a","b","c"]+[1,2,3] What does the line: my_list[3] return?

1

In the string "Hello", what is the index of the character: e?

1

Given the following lines of code, what is returned and what is its type for each labeled line 1 - 5: a = 2.5 b = 3 c = 5 a + b # Line 1 c / a # Line 2 float(c // b) # Line 3 str(c % b) # Line 4 int(b * a ) # Line 5

1. 5.5, float 2. 2.0, float 3. 1.0, float 4. "2", str 5. 7, int

Assuming the following declaration: a,b,c = 100,0,2 What is printed when the following line is executed: print(a + b)

100

Assuming we have the following dictionary definition: contacts = {"joe":1000, "bob":1301, "sue":4444} what does contacts["joe"] evaluate to?

1000

Assuming the following lines of code: my_list = [1,2, 'hello', 5] my_list[2] = 5 the function call: sum(my_list) returns what value?

13

What is the output of the following code? my_dict = {1:2, 2:3, 4:5} my_dict[1] = 10 print(my_dict[1] + my_dict[2])

13

Given the function definition def add(a,b): if a < 0: return b + b return a + b What does the call add(-3,7) return?

14

Assuming the following function definition, def fun_one(my_int1, my_int2 = 0, my_int3=1): return my_int1 ** 2 * my_int2 + my_int3 what value is returned when the function call: fun_one(5,my_int3=2) is made?

2

What does the line: len([1,2,3],[5,6,7,8]) return?

2

What is the output of the following code? num_one = 3 num_two = 2 num_three = 1 if num_one <= num_two : print(1) elif num_one >= num_two : print(2) elif num_one > num_two : print(3) else : print(4)

2

There are 3 boxes. Box 1 is labeled "Apples", Box 2 is labeled "Oranges", and Box 3 is labeled "Apples and Oranges". You know that all the boxes are labeled incorrectly. To fix the labels, you are only allowed to pick from one box. Which box (Type 1, 2, or 3 in the blank) would you pick from to start properly labeling?

3

What is the output of the following code? my_dict = {1:2, 2:3, 4:5} print(len(my_dict))

3

Which of the following is an example of a Boolean expression?

3 <= 4

What value is returned when the following line of code executes?

3.0

Assume to following declarations: a_list = [1,2,3] b_list = a_list b_list[1] = 0 What is returned when the following function call is made: sum(a_list)

4

What is the output of the following code? x = 3 if x >= 0 : x = 4 else : x = 5 print(x)

4

Select all expressions that evaluate to True

4 <= 4 365 == 365 1 != 25 and 3 < 2 + 5 3 * 3 != 3

What is the output of the following code: my_var = 2 + 1 * 3 this _var = my_var + 1 print(my_var)

5

What value does math.hypot(3,4) return? *hint* the hypot function returns a float type

5.0

Assuming the following declaration: a_tuple = 2,4,5 b_tuple = a_tuple + (2,4,5) What is printed when the following line is executed: print(len(b_tuple))

6

Copy of Assume to following declarations: a_list = [1,2,3] b_list = a_list[:] b_list[1] = 0 What is returned when the following function call is made: sum(a_list)

6

What is the output of the following code: my_var = 2 + 1 * 3 this _var = my_var + 1 print(this_var)

6

Use the following code snippet to answer the question. When calling my_function(my_arg), what gets copied into my_param? def my_function(my_param): print(my_param) my_arg = 5 my_function(my_arg)

A reference to the object held by my_arg

An ________ is a process or set of rules to be followed in calculations or other problem solving operations.

Algorithm

Select the option that is FALSE

An int divided by an int(with /) results in an int

According to the book, we like our programs to have three qualities. Two of the qualities are Readibility and Robustness. What is the Third?

Correctness

What does it mean for software to be open source?

Development is often done by a community of developers The code is freely available Development is often done by a community of developers

According to the book, we like our algorithms to have four qualities. Three of the qualities are Detailed, Specific (as to its behavior) and General purpose. What is the Fourth?

Effective

Select all rules/conventions for naming code elements in python

Every name must begin with a letter or underscore The name cannot be a python keyword The name can be of any length After the first letter, the name may contain any combination of letters, numbers, or underscores The name cannot contain delimiters/punctuation, or operators Names are case sensitive Numbers are not allowed as the first character Multiple word names are linked together with underscores

Given the function definition def grade_printer(perc): if perc > 0: print("F") elif perc > 60: print("D") elif perc > 70: print("C") elif perc > 80: print("B") elif perc > 90: print("A") else: print("Invalid") What is printed when the function invocation/call grade_printer(80) is made?

F

Dictionaries are immutable.

False

In Python, a method is another name for a function

False

In a dictionary, a value maps to a single key.

False

Strings can store a collection of any object, where Lists can only store a collection of characters.

False

To use an if, you must have an else that follows

False

What does the expression (True and False) or (False and True) evaluate to?

False

Put the four steps of the machine cycle in order.

Fetch Decode Decode Execute Store

When we try to open a file that doesn't exist, we get a FileNot_____Error

Found

Johnny's mother had three children. The first child was named April. The second child was named May. What was the third child's name?

Johnny

Functions that do not have return statements return what special value by default?

None

What are the three required characteristics of a computer?

Output Input Computation

A ________ is an implementation of an algorithm in a particular language to run on a particular kind of computer.

Program

If a programmer accounts for errors in the design of a program and devises tests to determine whether or not the program satisfies the original design and all other cases, this is a demonstration of ________.

Robustness

The line of code: "This is a test".replace("e", "oa") returns what string?

This is a toast

Assuming num_str = "0123456789", what does: "3" in num_str evaluate to?

True

Every variable created in a python program is considered an object

True

If x is -3, what does x >= -3 evaluate to? *Hint* Consider Python's case sensitivity

True

In Python, a string can be surrounded by either single quotes or double quotes

True

In a python dictionary, values may be anything, but keys can only be immutable objects

True

Indexing and slicing of lists is exactly the same as it is in Strings.

True

Is it possible for a loop to run "forever"?

True

To use an else, you must have an if before it

True

What does "abc" < "abcd" evaluate to?

True

What does the expression (3 != 5) and (0 > 0 or -1 <= 1) evaluate to?

True

When trying to do arithmetic with a string, we get a ________

TypeError

What is Python's default character encoding scheme?

UTF-8

When we try to convert a string of letters to an integer, we get a ________

ValueError

Assume the following assignment: a,b,c = "Watch out, Batman!".split("a") What is the output of print(a)?

W

Given the following snippet of code, what is printed out (Don't include quotation marks)? my_str = "abc" def fun_one(my_param): my_param = "def" fun_one(my_str) print(my_str)

abc

Assuming abc_str = "abcdefg", what substring does abc_str[:4] return?

abcd

Which option contains only python keywords?

and, del, from

What does the append method on a list do?

appends an element to the end of the list

Assuming abc_str = "abcdefg", what substring does abc_str[1:4] return?

bcd

Python's internal data type for values True and False is _________

bool

A boolean ________ can evaluate to either True or False

condition

When creating copies of objects, to ensure that all of the values are copied and not just references to the objects that hold those values, you need to use the ________ function from the copy module.

deepcopy

In a try-except construct, each ________ clause has associated with it a particular error name, and a suite of code that will run if that error occurs

except

A ________ is a collection of bytes of data that usually resides permanently on a disk.

file

In Python, the two different repetition constructs are while and ________ loops

for

What string method is used to format the output to the console?

format()

What is returned when the function call type(a) is made in the following code: a = 7 type(a)

int

The == operator is used to determine when two values are equal. What operator is used to determine when two variables refer to the same object

is

To check if two objects are the same object, use the keyword ________

is

For the list constructor to work, its argument must be a collection that is ________.

iterable

To convert a tuple to a list, use the ________ constructor

list()

What is the output of this for loop? some_string = "moo" for this_letter in some_string : print(this_letter)

m o o

Select all the options that are other names for dictionaries

map associative array

A clerk at a butcher shop stands five feet ten inches tall and wears size 13 sneakers. What does he weigh?

meat

Before Mt. Everest was discovered, what was the highest mountain in the world?

mt. Everest

If an object is ________, that means the elements in the collection can be changed after it is initially created.

mutable

Given the following code segment, select all of the following variables that are considered "local" to the function fun_one: my_var1 = "abc" def fun_one(my_var2): my_var3 = "def" return my_var1 + my_var2 + my_var3

my_var3 my_var2

Assume the following assignment: a,b,c = "Watch out, Batman!".split("a") What is the output of print(c)?

n!

Given the function definition def is_even(num): if num%2 == 0: return True return False What is printed when the function call/invocation is_even(32) is made?

nothing

Iteration is the process ...

of examining all elements of a collection, one at a time

The python ________ command/function sets up a connection and returns the file object associated with the connection.

open

Select the option that properly creates a file object specifying that we want to read from a file called "fileone.txt"

open("fileone.txt","r")

Select the option that properly creates a file object specifying that we want to write to a file called "fileone.txt"

open("fileone.txt","w")

When the same symbol in program might have different uses based on context (e.g. a + symbol being used for addition and concatenation), that is referred to as __________

operator overloading

Select the option that properly creates a file object and writes the first 5 letters of the alphabet to the first five lines of a file called "alpha.txt"

out_file = open("alpha.txt","w") for char in "abcde": print(char, file=out_file) out_file.close()

Functions that do not have return statements are often called ________.

procedures

The process of taking existing code and modifying it such that its structure is somehow improved but the functionality of the code remains the same is called ________

refactoring

The association of a vehicle name to an object is often referred to as a ________ in Computer Science.

reference

What is the pop method used for in regard to lists?

removes and the element at the end of the list and return that element

The following float precision descriptor specifies a precision of 3 digits to the ________ of the decimal point: .3f

right

To indent code in Python, it is recommended to use 4 ________

spaces

What is returned when the function call type(b) is made in the following code: b = "45" type(b)

str

punctuation, digits, asci_lowercase, and whitespace are all groups of characters defined in the ________ module

string

In a try-except construct, the ________ suite contains the code that might cause runtime errors

try

To convert a list to a tuple, use the ________ constructor

tuple

________ are essentially immutable lists. An example of one is: (1,3,5)

tuples

A(n) _________ is a name the programmer creates to represents a value, another program, a set of data, or a file

variable

Which line of code is an expression and evaluates to True when x is equal to 7?

x == 7

What is the output of the following code? x = 7 y = 8 if x == y : print("x equals y") elif x < y : print("x is greater") else : print("y is greater")

x is greater

Of the following, which is the largest?

yottabyte

What characters are used in a format string to represent that a substitution will take place at that location in the string?

{}


संबंधित स्टडी सेट्स

Chapter 12 Supply Chain Management in the Service Industry

View Set

Article 250 Grounding and Bonding

View Set

ISE 224 Chapter 3 Quiz Questions

View Set

SIE EXAM PREP Chapter 02: Overview of Regulation

View Set