CS 105 Final Exam

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

true or false: In Python, a function can return only one value.

false

true or false: There is a computer on the internet that can convert any computer's name (e.g., docs.google.com) into its IP address.

false

true or false: The + operator on lists (e.g., list1 + list2) will add the contents of the second list to the first list.

false - it will create a new list

true or false: Web pages use the Python language to implement interactive features.

false - javascrpt\

true or false: The replace method on strings modifies the string to replace all occurrences of one substring with another.

false - since strings are immutable, the replace method doesn't modify an existing string. it creates. anew string

true or false: Python lists can hold only objects of type int, float, and string.

false, lists can hold any type of object

true or false: HTML is the protocol used by the WWW to transfer documents between computers.

false- HTTP

true or false: An operating system is a hardware component that executes the instructions of a computer program.

false- a CPU does this

true or false: A while True: loop will never end.

false- a break statement could end it

true or false: The file on disk is updated immediately when a file.writeoperation is executed in Python.

false- disks are slow

true or false: All files have a file extension (e.g., .html, .docx, .txt).

false- file extensions are optional

true or false: In Excel, $A2 is an absolute reference.

false- it is not completely absolute, because it is still relative to whatever row it is moved/copied to. to be absolute, it would need $ in front of both of its column and row identifiers

true or false: The creation of functions in the global scope is generally discouraged.

false- most functions are defined in the global scope so that they can be invoked by any other function

true or false: When a program is run on the command line, we can pass it arguments like we are calling a function using a comma-separated list.

false- programs run from the command line can be given arguments, what are command line Orients but these are specified using a white space separated ist

true or false: The use of the file.write() method controls whether the data written to a file is appended to the end of the file or overwrites its contents.

false- whether appending overwriting occurs is controlled how the file is opened bu the mode parameter

true or false: every function in excel has at least one argument

false. PI() does not

true or false: The enumerate function allows a while loop to be used where a for loop would otherwise be required.

false. actually, the opposite. without enumerate, for generally only have access to the values of each element of a collection. enumerate provides acmes to the index as well

code reading problem x is a list o integers and variable y is an integer: def f(x,y): for i, val in enumerate(x) if val ==y: return i return none

if y is in the list, it returns the lowest index where it can be found

When does the value of an actual parameter of a function change? (a) Only when the parameter is a mutable type and you mutate the formal parameter (i.e., append an item to a list or change the value of an item in the list such as x[0] = 4). (b) Only when the parameter is a mutable type and you assign a new value to the formal parameter (i.e., the parameter is a list and you assign it to a new list such as x = [2, 3, 4]). (c) Any change to a formal parameter affects the corresponding actual parameter. (d) Whenever the parameter is a mutable type

A

Which of the following is not a Python type-conversion function: (a)abs (b)round (c)float (d)Int

A

The part of a program that uses a function is called the: (a) user (b) caller (c) statement (d)callee

B

Which of the following statements is true? (a) A for loop may have an if statement nested inside it. (b) all of the answers (c) An if statement may have a for loop nested inside it. (d) An if statement may have another if statement indented beneath it.

B- conditions and loops can be arbitrarily nested within each other

A structure in which one decision leads to another set of decisions, which leads to another set of decision, etc, is called a decision _____: (a) web (b) network (c) tree (d)trap

C

In modern Python, an int value that grows larger than the underlying hardware integers: (a) causes an overflow (b) converts to a float (c) uses more memory (d) breaks the computer

C

What is the purpose of the statement if __name__ == '__main__':? (a) none of the answers (b)to check if the name of a Python program is main. (c) to check if a Python file was executed or imported. (d)it may be an error unless the program included a line that set __name__ to a string value.

C

A statement that controls the execution of other statements is called a (a) boss structure (b) super structure (c) branch (d) control structure

D

Assuming that the variable x is defined, which of the following statements is true about the Python expression x == 3 or 4? (a) It is an invalid statement and the Python interpreter will indicate it is a syntax error. (b)I t will be True if x is 3 or if x is 4, and False for any other values. (c) It will always be False. (d) It will always be True.

D

How do you determine which actual parameter to assign to each formal parameter? (a) You manually assign each parameter at the beginning of the function. (b) You can only pass one parameter to a function. (c) The names of the formal parameters must match. (d) The order of the parameters indicates how they are assigned.

D

In Excel, A 3D reference is one that references one cell, but on a different worksheet than the sheet containing the reference.

FALSE

true or false: Global variables need to be declared as global within functions that want to read or write their values.

FALSE

true or false: Every computer on the internet has a unique domain name.

false

Write a statement that takes a variable named open_file that contains a file object and reads the next 12 characters into a variable named author.

author= open_file.read(12)

true or false: Good practice suggests using tabs to indent if statements and spaces to indent functions

false

code reading problem: def f(X): y=1 while x>9: y+=1 x //=10 return y

counts how many digits a number has

Write a statement that inserts the value 'exercise' into the list daily_list so that it becomes the element at index 6.

daily_list.insert(6, 'exercise')

Write a statement that opens a file named 'README.txt' for appending and assigns the resulting file object to a variable named f.

f= open('README.txt', 'a')

Any document containing HTML tags is considered an HTML 5 document.

false

Modern browsers do their best to render broken HTML pages, so it can be hard to know if HTML that you've written is standards compliant.

false

true or falsE: Input validation means prompting a user when input is required.

false

true or false In Python, the sum() function ignores any non-numerical values (e.g., strings) in a list that it is provided.

false

Write a statement that sorts in reverse order (from largest to smallest) the list locations in place.

locations.sort(reverse=True)

code reading problem: x is a list of numbers y= x[0] for val in x: if val>y y=val print(y)

prints the largest value in a list

code reading problem: x and y are lists def(x,y): return x+y

produces a list containing all of the elements of x followed by all the elements of y

true or false: Python is a compiled language.

python is an interpreted language

Write a statement that creates a new list called responses_sorted that is a sorted version of the list responses, without changing the list responses.

responses_sorted= sorted(responses)

code reading problem: def f(x,y,z): return (y-z) < x < (y+z)

returns whether a pair of numbers are within a given tolerance

code reading problem: x-=1

subtracts x by 1 and then stores that value in x

In Excel, VLOOKUP can ONLY search for a value in the first column of a given table.

true

true or false: Expressions are built from literals, variables, and operators.

true

true or false: HTML5 tries to separate the content of a web from the way that it appears and any interactive features.

true

true or false: In Excel, A2 is a relative reference.

true

true or false: Strings are compared by lexicographic ordering.

true

true or false: The sorted() function takes an optional reverse parameter that lets you sort from largest to smallest.

true

true or false: When computers communicate using HTTP, they use 3 digit status codes to indicate if a problem occurred and which one.

true

true or false: function calls are a kind of expression in python

true

true or false: functions can contain multiple return statements

true

true or false: in python, integers are immutable.

true

true or false: Anything implemented in a for loop can be implemented in as a while loop.

true - while is lower level than for

true or false: continue statements are generally conditionally executed (i.e., in the body of an if statement).

true- they are generally conditional because the loop will automatically go to the beginning of the next iteration when current iteration ends

true or false: the input() function always returns a string

true. if you want it to be a number you have to convert it using the int() function.


Kaugnay na mga set ng pag-aaral

Mastering Chapter 8: Intro to Metabolism

View Set