Computer Science fundamentals

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A function that returns an integer value grater than 0 is called a boolean function. True or False?

False

A variable that has a data type of "str" cannot be part of a compound data type True or False?

False

Functions can only return boolean expressions. True or False?

False

Given a Python dictionary d and a value v, it is efficient to find the corresponding key: d[k] = v. True or False?

False

In Python, a list of characters is the same as a string. True or False?

False

One way to generalize a function is to replace a variable with a value. True or False?

False

Portability means the program is written in small chunks of code. True or False?

False

Repeated execution of a set of programming statements is called repetitive execution. True or False?

False

String objects are modified with string slices. True or False?

False

The following Python code succeeds in modifying the first character of the string to "Y". fred = "Hello" fred[0] = "Y" True or False?

False

The modulus operator is the same as the divide operator. True or False?

False

Traversal can only be accomplished with the "while" loop. True or False?

False

What is the value of the following Python expression? "Xanadu" > "Yellowstone"

False

When defining a Python function that has no parameters, the parentheses that follow the function's name are optional. True or False?

False

A program is a sequence of instructions that specifies how to perform a computation. True or False?

True

A script usually contains a sequence of statements. If there is more than one statement, the results appear one at a time as the statements execute. True or False?

True

An algorithm is a general process for solving a category of problems. True or False?

True

An expression is a combination of values, variables, and operators. If you type an expression on the command line, the interpreter evaluates it and displays the result. True or False?

True

Encapsulation is the process of wrapping a piece of code in a function True or False?

True

Learning to debug can be frustrating, but it is a valuable skill that is useful for many activities beyond programming. True or False?

True

Python allows while loops inside while loops and if statements within the body of if statements. True or False?

True

Python dictionaries are mutable. True or False?

True

The acronym PEMDAS is a way to remember the order of operations in Python. True or False?

True

The operands of the logical operators should be boolean expressions, but Python is not very strict. Any nonzero number is interpreted as True. True or False?

True

True or False: A local variable is a variable defined inside a function that can only be used inside its function.

True

True or False: Learning to debug can be frustrating, but it is a valuable skill that is useful for many activities beyond programming.

True

With built in functions, it is generally acceptable to take a "Leap of Faith". True or False?

True

Programmers generally choose names for their variables that are meaningful and document what the variable is used for. True or False?

True or False?

What is the output of the following Python statements? def recurse(a): if (a == 0): print(a) else: recurse(a) recurse(0) a. 0 b. 1 c. no output d. RuntimeError: maximum recursion depth exceeded

a. 0

What output will the following Python program produce? n = 10 while n != 1: print (n,) if n % 2 == 0: # n is even n = n // 2 else: # n is odd n = n * 3 + 1 a. 10 5 16 8 4 2 b. None an error will be displayed c. 8 4 2 d. 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2

a. 10 5 16 8 4 2

What output will the following code produce? def area(l, w): temp = l * w; return temp l = 4.0 w = 3.25 x = area(l, w) if ( x ): print (x) a. 13.0 b. 0 c. Expression does not evaluate to boolean true d. 13

a. 13.0

What is the value of the variable index after the Python code below is executed? word = 'bAnana' index = word.find('a') a. 3 b. 1 c. 2 d. 5 e. 0

a. 3

What is the output of the following Python statements? x = 5 if x % 2 == 1: print (x) else: print (x, x%2) a. 5 b. (5, 1) c. 2 d. (5, 0)

a. 5

What output will the following statements produce using Python IDLE in interactive mode? a. 7 b. 5 c. 2 d. an error message will occur

a. 7

The following Python code illustrates what programming concept? bruce = 5 print (bruce,) bruce = 7 print (bruce) a. Reassignment b. Iteration c. Logical operators d. Conditionals

a. Reassignment

The following Python script will generate an error when executed. What is the cause of the error? def function2(param): print (param, param) print (cat) def function1(part1, part2): cat = part1 + part2 function2(cat) chant1 = "See You " chant2 = "See Me " function1(chant1, chant2) a. The variable cat is local to function1 and cannot be used in function2 b. The variable param is used twice in function2 and this is illegal c. Function2 does not have a return value defined d. Function1 does not have a return value defined

a. The variable cat is local to function1 and cannot be used in function2

Consider the following text from a Python interpreter. >>> print(2 + 2) 4 What is the text "print" called? a. a function b. an operator c. a prompt d. a statement e. a value

a. a function

What do we call the value provided to a function when the function is called (which is assigned to the corresponding parameter in the function)? a. argument b. return value c. method d. the special value None e. global variable

a. argument

The statements inside of a Python loop are known as the ____ of the loop. a. body b. expression c. counter d. block

a. body

What is the output of the following Python 3 program? mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"] a=0 while a < 8: print(mylist[a],) a = a + 2 a. now is the time b. now is the time for c. four score and seven years d. now four is score the and seven time years for

a. now is the time

Which of the following is an invalid Python assignment statement? a. a = b = 123 b. '3' = 3 c. x = int("123") d. y = None e. z = "hi" * 10

b. '3' = 3

Which of the following is not a valid Python numeric literal: a. 123 b. 0123 c. 0.00 d. 12.3 e. 0.75

b. 0123

What is the output of the following Python statements? def recurse(a): if (a == 1): print(a) else: recurse(a) recurse(1) a. 0 b. 1 c. no output d. RuntimeError: maximum recursion depth exceeded

b. 1

What is the output of the following Python 3 statements? x=1 y=2 if x == y: print (x, "and", y, "are equal") else: if x < y: print (x, "is less than", y) else: print (x, "is greater than", y) a. 1 and 2 are equal b. 1 is less than 2 c. 1 is greater than 2 d. 2 is greater than 1

b. 1 is less than 2

What is the output of the following Python statements? percentage = ( 60 * 100) // 55print (percentage) a. percentage b. 109 c. 109.0909090909091 d. 109.0

b. 109

What is the output of the following Python program? mylist = [ [2,4,1], [1,2,3], [2,3,5] ] total = 0 for sublist in mylist: total += sum(sublist) print(total) a. 14 b. 23 c. 0 d. 13

b. 23

What output will the following Python statement produce? >>> print (2*3-1) a. 6 b. 5 c. 4 d. 3

b. 5

What output will the following python commands produce: x = 5 if x % 2 == 0: print (x) else: print (x, x%2) a. 5 b. 5 1 c. 2 d. 5 0

b. 5 1

What does Python function subroutine do? def subroutine( n ): while n > 0: print (n,) n = n - 1 a. Counts from 10 down to 0 and displays each number b. Counts from n down to 1 and displays each number c. Calculates the sum of n numbers greater than 0 d. Calculates the mean of n

b. Counts from n down to 1 and displays each number

In the following segment of Python code, what do we call the portion of the statement that follows the dot ('.capitalize')? str.capitalize('maryland') a. Module b. Method c. Attribute d. Function name

b. Method

What output will the following Python script produce? def function2(param): print (param, param) def function1(part1, part2): cat = part1 + part2 function2(cat) chant1 = "See You " chant2 = "See Me " function1(chant1, chant2) a. See You See Me b. See You See Me See You See Me c. See Me See Me See You See You d. None it would generate an error

b. See You See Me See You See Me

Expressions evaluate to either True or False. What will be the output of the following Python 3 program? if "Ni!": print ('We are the Knights who say, "Ni!"') else: print ("Stop it! No more of this!") a. Stop it! b. We are the Knights who say, "Ni!" c. Stop it! No more of this!" d. No output will be produced

b. We are the Knights who say, "Ni!"

What is the output of the following Python program? fruit = "banana" letter = fruit[1] print (letter) a. b b. a c. n d. banana

b. a

Consider the following text from a Python interpreter. >>> print(2 + 2)4 What is the text "+" called? a. a function b. an operator c. a prompt d. a statement e. a value

b. an operator

Consider the following text from a Python interpreter. >>> print(2 + 2) 4 What is the text "+" called? a. a function b. an operator c. a prompt d. a statement

b. an operator

What is the output of the Python code below? s = "help" for letter in s[1:]: last = letter break print(last) a. h b. e c. ! d. p e. l

b. e

A development approach that that is intended to avoid a lot of debugging by only adding and testing small amounts of code at a time is called. a. structured development b. incremental development c. unit testing d. Systems development life cycle

b. incremental development

What is the output of the Python method call below? "bib".find('b', 1, 2) a. 0 b. 2 c. -1 d. syntax error e. 3

c. -1

What output will the following Python 3 statement produce? >>> print (1,000,000) a. 1.0 b. 1,000,000 c. 1 0 0 d. Error invalid type

c. 1 0 0

What output will the following Python statements produce? >>>percentage = ( 60.0 * 100.0 ) / 55.0 >>>print (percentage) a. percentage b. 109 c. 109.0909090909091 d. 109.0

c. 109.0909090909091

What output will the following python command produce: >>> percentage = float ( 60 * 100) / 55 >>> print (percentage) a. percentage b. 109 c. 109.0909090909091 d. 109.0

c. 109.0909090909091

What is the output of the following statements? pi = float(3.14159) print (pi) a. 3 b. 3.0 c. 3.14159 d. 0

c. 3.14159

What output will the following Python statements produce? >>> print (2*(3 - 1)) a. 6 b. 5 c. 4 d. 3

c. 4

What is the output of the Python code below? my_list = [3, 2, 1] print(my_list.sort()) a. 0 b. {1, 2, 3} c. None d. syntax error e. [1, 2, 3]

c. None

For the Python program below, will there be any output, and will the program terminate? while True: while 1 > 0: break print("Got it!") break a. Yes and no b. No and no c. Yes and yes d. No and yes e. Run-time error

c. Yes and yes

Assume that d is a Python dictionary. What does the following Python code produce? d.items() a. a histogram b. an inverted dictionary c. a list of tuples d. a lookup e. a reverse lookup

c. a list of tuples

Consider the following text from a Python interpreter. >>> print(2 + 2) 4 What is the text ">>>" called? a. a function b. an operator c. a prompt d. a statement e. a value

c. a prompt

What is the return type of the Python function shown below? def is_divisible(x, y): return (x % y) == 0 a. int b. float c. bool d. string e. NoneType

c. bool

In Python, the '+' operator can be used with numbers and with strings. What is a property that number addition has, but string concatenation does not? a. numeric addition is allowed on right-hand side of assignment statement b. more than one numeric addition per expression is allowed c. expression value does not depend on the order of numeric addition operands d. numeric addition is fast to execute e. numeric addition needs 2 operands

c. expression value does not depend on the order of numeric addition operands

What is the output of the following Python program? mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"] print(" ".join(mylist[1::2])) a. now is the time b. now is the time for c. four score and seven years d. now four is score the and seven time years for

c. four score and seven years

Using keywords for variable names will result in a ________________ a. runtime error b. compile error c. syntax error d. semantic error

c. syntax error

What does the Python interpreter output for the following input? >>> 1,234.567,890 a. 1234 b. 1234.6 c. 1234.56789 d. (1, 234.567, 890) e. SyntaxError: invalid token

d. (1, 234.567, 890)

What is the output of the following Python program? index = "Ability is a poor man's wealth".find("W") print(index) a. 24 b. 0 c. 23 d. -1

d. -1

What is the output of the following Python 3 statements? x=2 y=1 if x == y: print (x, "and", y, "are equal") else: if x < y: print (x, "is less than", y) else: print (x, "is greater than", y) a. 1 and 2 are equal b. 1 is less than 2 c. 1 is greater than 2 d. 2 is greater than 1

d. 2 is greater than 1

What is Python's response to the command: type(123)? a. <class 'float'> b. <class 'bool'> c. SyntaxError: invalid syntax d. <class 'int'> e. <class 'str'>

d. <class 'int'>

What is the output of the Python code below? n = int(10.) print(isinstance(n, float), isinstance(n * 1.0, float)) a. False b. True False c. True True d. False True e. False False

d. False True

What is the output of the following Python statements? def recurse(a): if (a == 0): print(a) else: recurse(a) recurse(1) a. 0 b. 1 c. no output d. RuntimeError: maximum recursion depth exceeded

d. RuntimeError: maximum recursion depth exceeded

Boolean expressions control _________________ a. recursion b. conditional execution c. alternative execution d. all of the above

d. all of the above

What is the output of the Python code below? print(dict().get("no", "help!")) a. True b. no c. no help! d. help! e. False

d. help!

If you assign the result a void function to a variable in Python, you get: a. an empty string b. the value -1 c. the value 0 d. the special value None e. an exception

d. the special value None

Which of the following types are allowed for Python dictionary keys? a. dictionary b. list c. list of dictionaries d. tuple e. All of the above

d. tuple

Will the Python code below print something? And will it terminate? def print_n(s, n): if n > 0: print(s) print_n(s, n-1) return n n = 3 while print_n("hi", n): print_n("there!", n) n = 0 a. no and no b. yes and no c. no and yes d. yes and yes e. syntax error

d. yes and yes

What is python's response to the command: type("0.123")? a. <class 'float'> b. <class 'bool'> c. SyntaxError: invalid syntax d. <class 'int'> e. <class 'str'>

e. <class 'str'>

Which of the following types are allowed for Python dictionary values? a. dictionary b. list c. list of dictionaries d. tuple e. All of the above

e. All of the above

What is the output of the Python code below? my_list = [3, 2, 1] print(my_list) a. 0 b. {3, 2, 1} c. None d. syntax error e. [3, 2, 1]

e. [3, 2, 1]

Assume that d is a Python dictionary. What does the following Python code produce? for k in d: if d[k] == v: return k a. a histogram b. an inverted dictionary c. a list of tuples d. a lookup e. a reverse lookup

e. a reverse lookup

Consider the following text from a Python interpreter. >>> print(2 + 2) 4 What is the text "4" called? a. a function b. an operator c. a prompt d. a statement e. a value

e. a value

What is the output of the code below assuming that global variable x has value 2 and global y has value 3? def f1(): return "ab" def f2(): return f1() * x def f3(): return f2() + f1() * y print(f3()) a. ababababababababab b. abababababab c. abababab d. ababab e. ababababab

e. ababababab


Ensembles d'études connexes

Lesson 8-G: Musculoskeletal System

View Set

RN Nursing Care of Children 2016 Bgood

View Set

Chapter 14: Business Forms/ Arrangements

View Set

anatomy-Peripheral and central nervous system

View Set

Karch Chapter 38: Agents to Control Blood Glucose Levels

View Set

ACCOUNTING BASICS- THINK LIKE AN ACCOUNTANT

View Set