CS 1101: Programming Fundamentals

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

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 variable that has a data type of "str" cannot be part of a compound data type

False

Handling an exception with a try statement is called throwing an exception.

False

In Python, a list of characters is the same as a string.

False

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

False

One way to generalize a function is to replace a variable with a value.

False

Portability means the program is written in small chunks of code.

False

String objects are modified with string slices.

False

The elements of a list are immutable.

False

To create a new object that has the same value as an existing object is knows as creating an alias.

False

Traversal can only be accomplished with the "while" loop.

False

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

False

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

False

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 reserved word that is used by the interpreter to parse programs.

Keyword

Any one of the languages that people speak that evolved naturally.

Natural Language

A special symbol that represents a simple computation like addition, multiplication, or string concatenation.

Operator

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

A unit of code that the Python interpreter can execute.

Statement

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

A program is a sequence of instructions that specifies how to perform a computation.

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

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

Functions allow the programmer to encapsulate and generalize sections of code.

True

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

True

Python dictionaries are mutable.

True

Python functions may or may not take arguments and may or may not return a result.

True

Python tuples are immutable.

True

The Python expression 'Unit 6'[-1] has value '6'.

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

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

True

A name that refers to a value.

Variable

What is the output from the following interactive Python statement? >>> '%d' % (0.1) a. '0' b. '0.1' c. TypeError: float argument required, not str d. TypeError: not all arguments converted during string formatting e. TypeError: not enough arguments for format string

a. '0'

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

a. 14

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

a. 24

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

a. 3

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'>

a. <class 'float'>

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

a. Lines in a file

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

a. [1, 4, 2, 3, 5]

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

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

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) 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) // 55 print (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 statements 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 output will the following Python statement produce? >>> print ((1+1)**(5-2)) a. 16 b. 8 c. 4 d. 2

b. 8

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

b. 8 ** 2

Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.isfile(cwd) a. ['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] b. False c. True d. /Users/me e. /Users/me/Documents/file.txt

b. False

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!") 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

An error that is detected while the program is running is referred to as: a. a syntax error b. an exception c. a compilation error d. a semantic error e. a late error

b. 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 result: result[val] = [key] else: result[val].append(key) a. a histogram b. an inverted dictionary c. a list of tuples d. a lookup e. a reverse lookup

b. an inverted dictionary

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

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

c. (1, 0, 0)

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

c. (1, 2, 2, 3)

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

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. The expression value does not depend on the order of numeric addition operands. d. Numeric addition is fast to execute. e. Numeric addition needs two operands.

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

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

Which of the following Python statements runs without error? a. open('three.txt').write(3) b. open('three.txt','w').write(3) c. open('three.txt','w').write(str(3)) d. All of the above e. None of the above

c. open('three.txt','w').write(str(3))

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

c. syntax error

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

Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.abspath(cwd) Select one: a. ['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] b. False c. True d. /Users/me e. /Users/me/Documents/file.txt

d. /Users/me

What is the output of the Python code below? print('%d + %d + %d = %d' % (1, 2, 3, 1+2+3)) a. 6 b. (1 + 2 + 3 = 6) c. None d. 1 + 2 + 3 = 6 e. "1 + 2 + 3 = 6"

d. 1 + 2 + 3 = 6

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

d. 17

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

d. 2 += 2

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

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

d. 21 * 60 + 21

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

d. 8 += 2

What does the following text indicate in a Python interpreter?>>> 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. e. The emoji for "food chain".

d. The interpreter is ready for you to enter code.

What is the value of the following Python expression? (0, 1, 5, 2) > (0, 1.0, 4, 3.1) a. 0 b. 1 c. False d. True e. syntax error

d. True

What is the output from the following interactive Python statement? >>> '%g' % (0,1) a. '0' b. '0.1' c. TypeError: float argument required, not str d. TypeError: not all arguments converted during string formatting e. TypeError: not enough arguments for format string

d. TypeError: not all arguments converted during string formatting

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

d. a statement

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

Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.join(cwd, 'Documents/file.txt') a. ['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] b. False c. True d. /Users/me e. /Users/me/Documents/file.txt

e. /Users/me/Documents/file.txt

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. YesMaybe e. NoMaybe

e. NoMaybe

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

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

e. keys


Kaugnay na mga set ng pag-aaral

Derivatives and Differentiability (3.6-3.9)

View Set

chapter 3 enviromental science test chapter 5 and 6

View Set

Prep U for Brunner and Suddarth's Textbook of Medical Surgical Nursing, 13th Edition Chapter 40: Assessment of Musculoskeletal Function

View Set

UNIT 3: Blood Vessels (Blood Flow) (Mylab and Mastering)

View Set

Marketing Chapters 11, 12,13,14,17,20

View Set