CS 1101

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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

5 1

What output will the following code produce? n = 10 while n != 1: print (n,end=' ') if n % 2 == 0: # n is even n = n // 2 else: # n is odd n = n * 3 + 1 Select one: a. 10 5 16 8 4 2 Correct 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

10 5 16 8 4 2

What is the output of the following Python program? mylist = [ [2,4,1], [1,2,3], [2,3,5] ] a=0 total = 0 while a < 3: b = 0 while b < 2: total += mylist[a][b] b += 1 a += 1 print(total) Select one: a. 14 Correct b. 23 c. 0 d. 13

14

What is the output of the following statements? pi = int(3.14159) print (pi) Select one: a. 3 Correct b. 3.0 c. 3.14159 d. 0

3

Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What is fin? Select one: a. A file object Correct b. A list of characters c. A list of words d. A string that may have a newline e. A string with no newline

A file object

Functions can only return Boolean expressions.

False

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 Me " chant2 = "See You " function1(chant1, chant2) Select one: a. See You See Me b. See Me See You See Me See You Correct c. See Me See Me See You See You d. None it would generate an error

See Me See You See Me See You

The Python expression 'Unit 6'[-1] has value '6'. Select one: True Correct False

True

The Python line below causes "5 dollars" to be printed. print('%d %s' % (5, 'dollars')) Select one: True Correct False

True

True/False: The % or modulus operator returns the remainder present when two integers do not divide evenly into one another Select one: True Correct False

True

With built in functions, it is generally acceptable to take a "Leap of Faith". Select one: True False

True

Expressions evaluate to either true or false. What will the output of the following code be when the expression "Ni!" is evaluated? if "Ni!": print ('We are the Knights who say, "Ni!"') else: print ("Stop it! No more of this!") Select one: a. Stop it! b. We are the Knights who say, "Ni!" Correct c. Stop it! No more of this!" d. No output will be produced

We are the Knights who say, "Ni!"

What will the contents of mylist be after the following code has been executed? >>> mylist = [1, 4, 2 3] >>> mylist.append(5) Select one: a. [1, 4, 2, 3, 5] Correct b. [5, 1, 4, 2, 3] c. [null] d. [1, 4, 2, 3]

[1, 4, 2, 3, 5]

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

a

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

a function

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

a list of tuples

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

a statement

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?

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

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. Select one: a. structured development b. incremental development c. unit testing d. Systems development life cycle

incremental development

A loop where the terminating condition is never achieved is called an _______ Select one: a. infinite loop Correct b. universal loop c. while loop d. for .. ever loop

infinite loop

If you use a Python dictionary in a for statement, it traverses the _____ of the dictionary. Select one: a. values and keys b. indices c. keys and values d. values e. keys Correct

keys

Occasionally, it is useful to have a body of an if statement that does nothing. In that case, you can use the following statement: Select one: a. # do nothing b. 0 = 0 c. Null d. pass e. Void

pass

Chained conditionals are used when there are three or more possibilities.

'True'.

The modulus operator is the same as the divide operator.

False

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

True

When a Python function is called, inside the function, the arguments are assigned to variables called parameters. Select one: True False

True

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

a prompt

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

a value

A Python loop where the terminating condition is never achieved is called _______. Select one: a. an infinite loop b. a universal loop c. a while loop d. a for .. ever loop

an infinite loop

Which one of the following words best describes formal languages? Select one: a. ambiguity b. literalness c. poetry d. prose e. redundancy

literalness

What is the output of the Python code below when run in script mode? y = 3 x = 5 x + y "x + y"

no output

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

'3' = 3

: To create a new object that has the same value as an existing object is know as creating an alias. Select one: True False Correct

'False'.

A variable that has a data type of "str" cannot be part of a compound data type Select one: True False Correct

'False'.

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

'False'.

Handling an exception with a try statement is called throwing an exception. Select one: True False Correct

'False'.

In Python, a list of characters is the same as a string. Select one: True False Correct

'False'.

The elements of a list are immutable. Select one: True False Correct

'False'.

Encapsulation is the process of wrapping a piece of code in a function

'True'

: The following code: for fruit in ["banana", "apple", "quince"]: print (fruit) will produce the following output: banana apple quince Select one: True Correct False

'True'.

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

'True'.

What is the value of the following Python expression? not(True and False) Select one: True Correct False

'True'.

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

(1, 0, 0)

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

(1, 234.567, 890)

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

-1

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

-1

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

0

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

0123

What output will the following python commands produce: 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) Select one: a. 1 and 2 are equal b. 1 is less than 2 Correct c. 1 is greater than 2 d. 2 is greater than 1

1 is less than 2

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 Select one: 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

10 5 16 8 4 2

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

109

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

109.0909090909091

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

109.0909090909091

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) Select one: a. 13.0 b. 0 c. Expression does not evaluate to boolean true d. 13

13.0

What output will the following Python statements produce? >>> n = 17 >>> print (n) Select one: a. (n) b. 17.0 Incorrect c. n d. 17

17

How many different values can a Boolean expression have? Select one: a. 3 b. 2 Correct c. infinite number d. 1 e. not defined

2

Which one of the following Python expressions computes the total number of seconds in 21 minutes and 21 seconds? Select one: a. 21 + 21 b. 21 + 60 c. "21 minutes" + "21 seconds" d. 21 * 60 + 21 e. seconds = 21 + "21 minutes"

21 * 60 + 21

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) Select one: a. 14 b. 23 Correct c. 0 d. 13

23

Given the following code, what will the output be? import string index = "Ability is a poor man's wealth".find("w") print(index) Select one: a. 24 Correct b. 0 c. 23 d. -1

24

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

24

What is the output of the following Python statements? pi = int(3.14159) print (pi) Select one: a. 3 b. 3.0 c. 3.14159 d. 0

3

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

3

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

3.14159

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

4

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

5

What output will the following Python commands produce? n = 10000 count = 0 while n: count = count + 1 n = n // 10 print (count) Select one: a. 5 b. 0 c. 10000 d. 1000

5

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

5

What output will the following python commands produce: n = 10000 count = 0 while n: count = count + 1 n = n // 10 print (count) Select one: a. 5 Correct b. 0 c. 10000 d. 1000

5

Which one of the following Python expressions computes the number of miles in 5 km, where one mile is 1.61 km? Select one: a. 5 * 1.61 Incorrect b. 5 / 1.61 c. 1.61 / 5 d. 1.61 + 5 e. miles = "5 km"

5 / 1.61

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

5 1

What output will the following code produce? print ("%s %d %f" % (5, 5, 5)) Select one: a. 5 5 5.000000 Correct b. 5 5 5 c. 5 5.000000 d. 0 5 5.0

5 5 5.000000

What output will the following statements produce using Python IDLE in interactive mode? >>> n = 2 >>> n += 5 >>> n Select one: a. 7 b. 5 c. 2 d. an error message will occur

7

What output will the following statements produce using Python in interactive mode? >>> n = 2 >>> n = n + 5 >>> n Select one: a. 7 b. 5 c. 2 d. an error message will occur

7

What output will the following Python statements produce? >>> print ((1+1)**(5-2)) Select one: a. 16 b. 8 Correct c. 4 d. 2

8

Which one of the following Python expressions has the value 64? Select one: a. 8 ^ 2 b. 8 ** 2 c. 8 +- 2 d. 8 += 2 e. 8 -+ 2

8 ** 2

Which one of the following Python expressions has the value 64? Select one: a. 8 ^ 2 b. 8 ** 2 Correct c. 8 +- 2 d. 8 += 2 e. 8 -+ 2

8 ** 2

Which one of the following Python expressions generates a syntax error? Select one: a. 8 ^ 2 b. 8 ** 2 c. 8 +- 2 d. 8 += 2 Correct e. 8 -+ 2

8 += 2

Which one of the following Python expressions generates a syntax error? Select one: a. 8 ^ 2 Incorrect b. 8 ** 2 c. 8 +- 2 d. 8 += 2 e. 8 -+ 2

8 += 2

Which one of the following Python expressions has the value 10? Select one: a. 8 ^ 2 b. 8 ** 2 c. 8 +- 2 d. 8 += 2 e. 8 -+ 2

8 ^ 2

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

<class 'float'>

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

<class 'int'>

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

<class 'str'>

What will the output of this program be when it is executed? def test_function( length, width, height): print ("the area of the box is ", length*width*height) return length*width*height l = 12.5 w = 5 h = 2 test_function(l, w, h) print ("The area of the box is ", length*width*height) Select one: a. A NameError because a variable not defined b. The area of the box is 125.0 c. The area of the box is 0 d. A SyntaxError due to illegal function call

A NameError because a variable not defined

A statement that creates a new variable and gives it a value. → assignment statement, Information in a program that is meant for other programmers (or anyone reading the source code) and has no effect on the execution of the program. → comment, The ability to combine simple expressions and statements into compound statements and expressions in order to represent complex computations concisely. → composition, To join two operands end-to-end. → concatenate, What the Python interpreter does to an expression to find its value. → evaluate, A combination of variables, operators, and values that represents a single result value. → expression, A Python data type that stores floating-point numbers. → float, A Python data type that holds positive and negative whole numbers. → int, A reserved word that is used by the interpreter to parse programs. → keyword, One of the values on which an operator operates. → operand, A special symbol that represents a simple computation like addition, multiplication, or string concatenation. → operator, A unit of code that the Python interpreter can execute. → statement, A Python data type that holds a string of characters. → str, A number or letter that can be stored in a variable or evaluated in an expression. → value, A name that refers to a value. → variable

A statement that creates a new variable and gives it a value. → assignment statement, Information in a program that is meant for other programmers (or anyone reading the source code) and has no effect on the execution of the program. → comment, The ability to combine simple expressions and statements into compound statements and expressions in order to represent complex computations concisely. → composition, To join two operands end-to-end. → concatenate, What the Python interpreter does to an expression to find its value. → evaluate, A combination of variables, operators, and values that represents a single result value. → expression, A Python data type that stores floating-point numbers. → float, A Python data type that holds positive and negative whole numbers. → int, A reserved word that is used by the interpreter to parse programs. → keyword, One of the values on which an operator operates. → operand, A special symbol that represents a simple computation like addition, multiplication, or string concatenation. → operator, A unit of code that the Python interpreter can execute. → statement, A Python data type that holds a string of characters. → str, A number or letter that can be stored in a variable or evaluated in an expression. → value, A name that refers to a value. → variable

Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What is line? Select one: a. A file object b. A list of characters c. A list of words d. A string that may have a newline Correct e. A string with no newline

A string that may have a newline

Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What is word? Select one: a. A file object b. A list of characters c. A list of words d. A string that may have a newline e. A string with no newline Correct

A string with no newline

An error in a program. → bug, The process of finding and removing any of the three kinds of programming errors. → debugging, Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are these kinds of languages. → formal language, A programming language like Python that is designed to be easy for humans to read and write. → high-level language, A program that reads another program and executes it. → interpreter, A programming language that is designed to be easy for a computer to execute; also called machine language or assembly language. → low-level language, Any one of the languages that people speak that evolved naturally. → natural language, To examine a program and analyze the syntactic structure. → parse, A property of a program that can run on more than one kind of computer. → portability, An instruction that causes the Python interpreter to display a value on the screen. → print statement, The process of formulating a problem, finding a solution, and expressing the solution. → problem solving, A sequence of instructions that specifies to a computer actions and computations to be performed. → program, A program stored in a file (usually one that will be interpreted). → script, The structure of a program. → syntax, One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language. → token

An error in a program. → bug, The process of finding and removing any of the three kinds of programming errors. → debugging, Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are these kinds of languages. → formal language, A programming language like Python that is designed to be easy for humans to read and write. → high-level language, A program that reads another program and executes it. → interpreter, A programming language that is designed to be easy for a computer to execute; also called machine language or assembly language. → low-level language, Any one of the languages that people speak that evolved naturally. → natural language, To examine a program and analyze the syntactic structure. → parse, A property of a program that can run on more than one kind of computer. → portability, An instruction that causes the Python interpreter to display a value on the screen. → print statement, The process of formulating a problem, finding a solution, and expressing the solution. → problem solving, A sequence of instructions that specifies to a computer actions and computations to be performed. → program, A program stored in a file (usually one that will be interpreted). → script, The structure of a program. → syntax, One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language. → token

What does Python function subroutine do? def subroutine( n ): while n > 0: print (n,) n = n - 1 Select one: 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

Counts from n down to 1 and displays each number

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

Counts from n down to 1 and displays each number

"Dead code" is code that performs calculations but never displays the results.

False

A function that returns an integer value grater than 0 is called a boolean function. Select one: True False

False

A variable that has a data type of "str" cannot be part of a compound data type Select one: True False Correct

False

In Python, a list of characters is the same as a string. Select one: True False Correct

False

In Python, the expression "a ** (b ** c)" is the same as "(a ** b)

False

One way to generalize a function is to replace a variable with a value. Select one: True Incorrect False

False

Portability means the program is written in small chunks of code. Select one: True False

False

Repeated execution of a set of programming statements is called repetitive execution. Select one: True False

False

String objects are modified with string slices. Select one: True False Correct

False

The elements of a list are immutable. Select one: True False Correct

False

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

False

The int function can convert floating-point values to integers, and it performs rounding up/down as needed.

False

This Python code: for fruit in ["banana", "apple", "quince"]: print (fruit) will produce this output: banana apple quince Select one: True Incorrect False

False

To create a new object that has the same value as an existing object is knows as creating an alias. Select one: True Incorrect False

False

Traversal can only be accomplished with the "while" loop. Select one: True False Correct

False

What is the value of the following Python expression? "Xanadu" > "Yellowstone" Select one: True False

False

When defining a Python function that has no parameters, the parentheses that follow the function's name are optional. Select one: True Incorrect False

False

string is a Python type that represents sequences of numeric values. Select one: True False

False

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

False True

Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What does the program loop over? Select one: a. Lines in a file Correct b. Lines in a list c. Words in a dictionary d. Words in a list e. Words in a string

Lines in a file

Expressions evaluate to either true or false. What will the output of the following code be when the expression "Ni!" is evaluated? if "Ni!": print ('We are the Knights who say, "Ni!"') else: print ("Stop it! No more of this!") Select one: a. Stop it! b. We are the Knights who say, "Ni!" c. Stop it! No more of this!" d. No output will be produced

Ni!

What is the output of the following Python program? try: fin = open('answer.txt') fin.write('Yes') except: print('No') print('Maybe') Select one: a. Yes b. No c. Maybe d. Yes Maybe e. No Maybe Correct

No Maybe

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

None

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

None

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

Reassignment

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

RuntimeError: maximum recursion depth exceeded

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) Select one: 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

See You See Me See You See Me

What will the output of this python program be? def test_function( length, width, height): print ("the area of the box is ",length*width*height) return length*width*height l = 12.5 w = 5 h = 2 test_function(l, w, h) Select one: a. The area of the box is 125 b. The area of the box is 125.0 c. The area of the box is 120 d. 125.0f

The area of the box is 125.0

What will the output of this python program be? def test_function( length, width, height): print ("the area of the box is ",length*width*height) return length*width*height l = 12.5 w = 5 h = 2 test_function(l, w, h) Select one: a. The area of the box is 125 b. The area of the box is 125.0 Correct c. The area of the box is 120 d. 125.0

The area of the box is 125.0

The correct answer is: An error in a program. → bug, The process of finding and removing any of the three kinds of programming errors. → debugging, Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. → formal language, A programming language like Python that is designed to be easy for humans to read and write. → high-level language, A program that reads another program and executes it. → interpreter, A programming language that is designed to be easy for a computer to execute; also called machine language or assembly language. → low-level language, Any one of the languages that people speak that evolved naturally. → natural language, To examine a program and analyse the syntactic structure. → parse, A property of a program that can run on more than one kind of computer. → portability, An instruction that causes the Python interpreter to display a value on the screen. → print statement, The process of formulating a problem, finding a solution, and expressing the solution. → problem solving, a sequence of instructions that specifies to a computer actions and computations to be performed. → program, A program stored in a file (usually one that will be interpreted). → script, One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language. → token, The structure of a program. → syntax

The correct answer is: An error in a program. → bug, The process of finding and removing any of the three kinds of programming errors. → debugging, Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. → formal language, A programming language like Python that is designed to be easy for humans to read and write. → high-level language, A program that reads another program and executes it. → interpreter, A programming language that is designed to be easy for a computer to execute; also called machine language or assembly language. → low-level language, Any one of the languages that people speak that evolved naturally. → natural language, To examine a program and analyse the syntactic structure. → parse, A property of a program that can run on more than one kind of computer. → portability, An instruction that causes the Python interpreter to display a value on the screen. → print statement, The process of formulating a problem, finding a solution, and expressing the solution. → problem solving, a sequence of instructions that specifies to a computer actions and computations to be performed. → program, A program stored in a file (usually one that will be interpreted). → script, One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language. → token, The structure of a program. → syntax

The correct answer is: Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. → formal language, Any one of the languages that people speak that evolved naturally. → natural language, An error that does not occur until the program has started to execute but that prevents the program from continuing. → runtime error, An error in a program that makes it do something other than what the programmer intended. → semantic error, The meaning of a program. → semantics, The structure of a program. → syntax, An error in a program that makes it impossible to parse — and therefore impossible to interpret. → syntax error, One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language. → token

The correct answer is: Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. → formal language, Any one of the languages that people speak that evolved naturally. → natural language, An error that does not occur until the program has started to execute but that prevents the program from continuing. → runtime error, An error in a program that makes it do something other than what the programmer intended. → semantic error, The meaning of a program. → semantics, The structure of a program. → syntax, An error in a program that makes it impossible to parse — and therefore impossible to interpret. → syntax error, One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language. → token

What does the following text indicate in a Python interpreter? >>> Select one: a. A syntax error has occurred. b. One value is much greater than another. c. Shift a value to the right. d. The interpreter is ready for you to enter code. Correct e. The emoji for "food chain".

The interpreter is ready for you to enter code.

The order in which statements are executed during a program run. → flow of execution, The first part of a compound statement, begins with a keyword and ends with a colon ( : ) → header, A statement that executes a function. It consists of the name of the function followed by a list of arguments enclosed in parentheses. → function call, A variable defined inside a function that can only be used inside its function. → local variable, A graphical representation of functions, their variables, and the values to which they refer. → stack diagram

The order in which statements are executed during a program run. → flow of execution, The first part of a compound statement, begins with a keyword and ends with a colon ( : ) → header, A statement that executes a function. It consists of the name of the function followed by a list of arguments enclosed in parentheses. → function call, A variable defined inside a function that can only be used inside its function. → local variable, A graphical representation of functions, their variables, and the values to which they refer. → stack diagram

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) Select one: 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

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

A program is a sequence of instructions that specifies how to perform a computation. Select one: True False

True

A property of a program that can run on more than one kind of computer is called portability. Select one: True 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. Select one: True Correct False

True

An algorithm is a general process for solving a category of problems. Select one: True 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. Select one: True Correct False

True

As programs get bigger and more complicated, they get more difficult to read. This is one reason why programmers should use comments in their code. Select one: True Correct False

True

Functions allow the programmer to encapsulate and generalize sections of code. Select one: True False

True

In a script, an expression all by itself is a legal statement, but it does not do anything. Select one: True False Incorrect

True

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

True

Python allows while loops inside while loops and if statements within the body of if statements. Select one: True False

True

Python functions may or may not take arguments and may or may not return a result. Select one: True Correct False

True

The * operator also works on strings for which it performs repetition.

True

The acronym PEMDAS is a way to remember the order of operations in Python. Select one: True False

True

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 Select one: a. Yes and no b. No and no c. Yes and yes d. No and yes e. Run-time error

Yes and yes

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 Select one: a. Yes and no b. No and no c. Yes and yes Correct d. No and yes e. Run-time error

Yes and yes

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

[3, 2, 1]

A Python string is a sequence of characters. You can access the string characters with the _______. Select one: a. () operator b. % operator c. dot operator d. // operator e. [] operator

[] operator

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

a reverse lookup

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())

ababababab

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

all of the above

Which of the following types are allowed for Python dictionary values? Select one: a. dictionary b. list c. list of dictionaries d. tuple e. all of the above Correct

all of the above

An error that is detected while the program is running is referred to as:

an exception

Assume that d is a Python dictionary. What does the following Python code produce? result = dict() for key in d: val = d[key] if val not in inverse: result[val] = [key] else: result[val].append(key) Select one: a. a histogram b. an inverted dictionary Correct c. a list of tuples d. a lookup e. a reverse lookup

an inverted dictionary

Assume that d is a Python dictionary. What does the following Python code produce? result = dict() for key in d: val = d[key] if val not in result: result[val] = [key] else: result[val].append(key) Select one: a. a histogram b. an inverted dictionary Correct c. a list of tuples d. a lookup e. a reverse lookup

an inverted dictionary

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

an operator

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)? Select one: a. argument Correct b. return value c. method d. the special value None e. global variable

argument

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

body

Programming languages are ______ languages that have been designed to express computations. Select one: a. informal b. mathematical c. formal Correct d. natural e. logical

formal

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])) Select one: a. now is the time b. now is the time for c. four score and seven years Correct d. now four is score the and seven time years for

four score and seven years

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. Select one: a. structured development b. incremental development Correct c. unit testing d. Systems development life cycle

incremental development

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

maximum recursion depth exceeded

Given the following code, what will the output be? mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"] a=0 while a < 7: print (mylist[a],) a += 2 Select one: a. now is the time Correct b. now is the time for c. for score and seven years d. now four is score the and seven time years for

now is the time

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 Select one: a. now is the time Correct b. now is the time for c. four score and seven years d. now four is score the and seven time years for

now is the time

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

syntax error

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

the special value None

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

tuple


Set pelajaran terkait

Yoder-Wise Ch 3 Legal/Ethical Issues

View Set

Pharmacology, Ch. 3: Toxic Effects of Drugs

View Set

Chapter: Basic Insurance Concepts and Principles

View Set

Chapter 16 Control Systems and Quality Management: Techniques for Enhancing Organizational Effectiveness

View Set

NX BASIC DESIGN KNOWLEDGE CHECKS

View Set