Python 2 exam, Python Ch 9, Control Structures Final (Chapters 3 and 4), Python Questions (Multiple Choice), Ch3 control statements, Chapters 9 Python

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

What will be assigned to s_string after the execution of the following code? special = '1337 Country Ln.' s_string = special[4: ] a. '1357' b. 'Country Ln. ' c. ' Country Ln.' d. Invalid code

' Country Ln.'

What will be assigned to s_string after the execution of the following code? special = '1337 Country Ln.' s_string = special[ :4] a. '1357' b. 'Country Ln.' c. ' Country Ln.' d. Invalid code

'1357'

What is the value of the variable string after the execution of the following code? string = 'Hello' string += ' world' a. 'Hello' b. ' world' c. 'Hello world' d. Invalid code

'Hello world'

What is the value of 'John'[0]?

'J'

Reference: Case Study 1 >>> name = "Roy G Biv" >>> first = name[0] >>> first >>> middleChar = name[4] >>> middleChar >>> name[-1] Refer to the session in the accompanying case study. What is printed after line 6?

'v'

Assume you have created a turtle instance. What is the result of calling the position method? a) (0) b) (0,0) c) (50,50) d) (100,100)

(0,0)

What are the valid indexes for the string 'New York'? a. 0 through 7 b. 0 through 8 c. -1 through -8 d. -1 through 6

0 through 7

How many times will the following print statement be executed? >>> for sides in range(8,100,8): print(sides,archimedes(sides))

12 times

How many times with a statement be executed in this loop? for i in range(5) a) 0 b) 1 c) 5 d) n

5

What is the result of the expression 15//2? a) 1 b) 7 c) 7.7 d) 8

7

What is the result of the expression 15/2? a) 1 b) 7 c) 7.5 d) 8

7.5

What is the Python prompt? a) >> b) >>> c) # d) =

>>>

What do you use to associate an object name with an expression in Python? a) object space b) key label c) assignment statement d) abstract reference

Assignment statement

What equation relates pi to the circumference of a circle? a) c = 2πr b) C = πr c) C = 2πd d) C = 2πa

C=2πr

Definition - A method that creates a new object

Constructor

What is the number of the first index in a dictionary?

Dictionaries are not indexed by number.

You have entered a calculation in the Python interpreter. To see the result of this calculation, which key would you press? a) spacebar b) tab c) enter (or return) d) =

Enter (Or Return)

Definition - A combination of operators and operands

Expression

True or False: At a high level, the Python interpreter simply does two things over and over again: 1) read, and 2) write

FALSE

True or False: The best way to learn Python is to read through a textbook before typing any commands to ensure that you understand the key concepts first

False

The find method finds the number of occurrences of one string within another. Under the American Standard Code for Information Interchange (ASCII), the letter 'a' corresponds to the number 0.

False False

The following Python statement prints even numbers in ascending order: list(range(10,2,-2)) Case Study 3 >>> ages = {'David':45,'Brenda':46} >>> ages {'Brenda':46, 'David':45} >>> Refer to the session in the accompanying case study. The reference ages refers to a list.

False False

What represents the number of times each value occurs in a set of data?

Frequency distribution

What technique enables you to go from a specific set of examples to a solution - to a solution that can be implemented as a program a) generalization b) simplification c) representation d) visualization

Generalization

What does the get method do if the specified key is not found in the dictionary?

It returns a default value.

What will be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna']

KeyError

What is the name of the formula that calculates pi using the following equation? π/4= 1/1 - 1/3 + 1/5 - 1/7 + 1/9....

Leibniz formula

Definition - Step-by-Step instructions that provide a solution to a problem

Program

True or False: The python language contains many abstractions that are built by using python elements. In other words, much of Python is written in Python

TRUE

True or False: When converting floating-point numbers to integers, Python always truncates the fractional part of the number

TRUE

Which of the following does not apply to sets?

The elements are in pairs.

The values() method returns a dict_values object that behaves much like a list of the values in a dictionary.

True

True or False: Computers are providing key help on the forefront of the biological research with protein "folding"

True

True/False: An exception handler is a piece of code that is written using the try/except statement.

True

True/False: Closing a file disconnects the communication between the file and the program

True

True/False: If the + operator is used on strings, it produces a string that is the combination of the two strings used as its operands.

True

True/False: Indexing works with both strings and lists.

True

True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.

True

True/False: The issubset method can be used to determine whether set1 is a subset of set2.

True

What is the result of the following code? 'bc' in 'abc'

True

Definition - Used by Python to classify different kinds of objects

Type

Case Study 2 1. >>> changelist = [1,2,"buckle my shoe",3,4,"shut the door"] 2. >>> changelist 3. 4. >>> changelist[2] = "the sky is blue" 5. >>> changelist 6. ?????? 7. >>> name = "Monte" 8. >>> name[2] = "x" 9. ?????? Refer to the session in the accompanying case study. What will be the output on line 9?

TypeError:object does not support item assignment

Definition - The name found on the left side of the equals sign as an expression

Variable

What is the name that allows us to locate a python object a) algorithm b) assignment c) operand d) variable

Variable

How is an empty list represented in Python?

[ ]

To add a single item to a set, you can use the set method _______________.

add

What function can be used to surround a string with spaces in order to make it a certain length?

center

One of the most often used measures of a collection of data is known as ____.

central tendency

The _______________ method clears the contents of a dictionary

clear

Which is an attribute of a turtle? a) color b) Forward c) Down d) Dot

color

Which would you use to delete an existing key-value pair from a dictionary?

del

What would you use if an element is to be removed from a specific index? a. del statement b. [1, 3, 5, 7, 9] c. index method d. slice method

del statement

A Python ____ is a collection of associated pairs of items where each pair consists of a key and a value.

dictionary

When a program needs to save data for later use, it writes the data in a(n) _______________.

file

Case Study 1 >>> myanswers = "ABEADBBACE" >>> ?????? print(answer) Output: A B E A D B B A C E Refer to the session in the accompanying case study. What program statements appear on line 2 to create the output listed in the case study?

for answer in myanswers:

Assume namesList contains a list of names (as strings). Write a for-loop that walks over the list and prints out all the names.

for n in namesList: print(n)

Tuples are _______________ , which means that once a tuple is created, it cannot be changed.

immutable

In order to use the sqrt() function, you must use this Python statement: a) use math; b) import math; c) math::sqrt(); d) return sqrt();

import math;

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the __________ operator.

in

The _______________ operator can be used to determine whether one string is contained in another string.

in

What is the membership operator for lists?

in

When implementing a substitution cipher in Python, use the ____ method to return the position of any letter in the alphabet.

index

Python uses the ____ function to ask the user for a single string.

input

What method can be used to place an item in the list at a specific index? a. append b. index c. insert d. Add

insert

Whole numbers in Python are called : a) complex numbers b) decimals c) floating point numbers d) integers

integers

Which method would you use to get all the elements in a dictionary returned as a list of tuples?

items

Which method would you use to returns all the elements in the dictionary as a list of tuples? a. list b. items c. pop d. keys

items

In a dictionary, you use a(n) _____ to locate a specific value. a. datum b. index c. item d. key

key

In a dictionary, you use a(n) __________ to locate a specific value.

key

What function returns the number of characters in a string?

len

Which would you use to get the number of elements in a dictionary?

len

The built-in function _______________ returns the length of a sequence.

len()

The _______________ method returns a copy of the string with all alphabetic letters converted to lower case.

lower()

Found by locating the item that occurs in the exact middle of a collection The most frequently occurring value in a collection Measure of how spread out data values in a collection are Calculated by adding up the values in a collection and dividing by the number of items

median mode dispersion mean

When calculating pi using the wallis formula, the accumulator variable.... a) must be initialized to zero b) is increased by two each iteration c) must be initialized to one d) is multiplied by two each iteration

must be initialized to one

Which step creates a connection between a file and a program? a. Open the file. b. Read the file. c. Process the file. d. Close the file.

open the file

What function converts a character to a number?

ord

What is the process used to convert an object to a stream of bytes that can be saved in a file?

pickling

Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary?

pop

The ____ list function removes and returns the last item in a list.

pop()

The turtle method ____ does not take any parameters a) forward b) position c) right d) fillcolor

position

The ___ statement is used to terminate a function a) return b) exit c) end d) quit

return

You can type commands interactively at the Python shell by opening the Python interpreter and starting a : a) expression b) listing c) session d) object

session

A(n) _______________ is an object that holds multiple unique items of data in an unordered manner.

set

A(n) _______________ is a span of items that are taken from a sequence.

slice

What is the [:] operator called?

slice

The third number in string slicing brackets or in the range() function represents the _______________ value.

step or increment

How does your text differentiate the three levels of problem-solving? a)input, variables, and output b) strategy, tactics, and tools c) analysis, implementation, and execution

strategy, tactics and tools

Which of the following is a constant in the math module? sqrt, tan, asin, e

tan

Reference: Case Study 2 1. def scramble2Encrypt(plainText ): 2, evenChars = "" 3. oddChars = "" 4. charCount = 0 5. for ch in plainText : 6. if charCount % 2== 0: 7. evenChars = evenChars + ch 8. else: 9. oddChars = oddChars + ch 10. charCount = charCount + 1 11 cipherText = oddChars + evenChars 12 return cipherText Refer to the code in the accompanying case study. What type of cipher has been implemented?

transposition

True/False: Invalid indexes do not cause slicing expressions to raise an exception.

true

True/False: The lstrip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.

true

What statement can be used to handle some of the run-time errors in a program? a. exception statement b. try statement c. try/except statement d. exception handler statement

try/except statement

Which method can be used to add a group of elements to a set?

update

What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)?

{ 1 : 'January', 2 : 'February', ... 12 : 'December' }

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'CA' in cities: del cities['CA'] cities['CA'] = 'Sacramento' print(cities)

{'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities)

{'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities)

{'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'}

What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = 5556666'

{'John' : '5556666', 'Julie' : '5557777'}

Case Study 3 >>> ages = {'David':45,'Brenda':46} >>> ages {'Brenda':46, 'David':45} >>> Refer to the session in the accompanying case study. What will be the output after the following statement? >>> ages['Kelsey']=19 >>> ages

{'Kelsey':19, 'Brenda':46, 'David':45}


Kaugnay na mga set ng pag-aaral

TEST FOR COMPUTER ON CHAPTERS 4,5,6!!

View Set

Marketing Ch 1: Overview of Marketing Assignment

View Set

Foundations of Nursing Chapter 10 Caring for Families

View Set

PAD add to sets, Quiz 3 notes PAD add to sets for exam, PAD recovery, PAD: Recovery and Mitigation Ch. 2-3, Ch.8 & 10

View Set

intro to phil hales bloomu final

View Set

chapter 1 of intor to nutrition study gide

View Set

Voice Data Video (VDV) Practice Test

View Set

UH Manoa - PH 203 (T. Lee) - Certification Test : How To Recognize Plagiarism

View Set

Vision & Human Eye Study Questions

View Set

The Reading and Writing Processes

View Set