Python midterm

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

Grover Cleveland served as president of the United States from 1885 to 1889 and from 1893 to 1897. Which expression correctly detects this range?

(1885 <= x <= 1889) or (1893 <= x <= 1897)

Which code is an example of an expression?

(x*y)/2

Which expression is most appropriate for randomly choosing a day of the week? - random.randrange(7) - random.randrange(1) - random.randrange(6) - random.randrange(8)

- random.randrange(7)

What are the possible values for random.randint(-4, 4)?

-4...4

What are the possible values for random.randrange(6)?

0...5

What is the base 2 representation of the decimal number: 35?

00100011

Python language began development in the late _____'s.

1980

A computer processor stores numbers using a base of _____.

2

What is the value of: 1 + int(3.5) / 2?

2.5

What is the final value of z? grades = { 'A': 90, 'B': 80, 'C': 70, 'D': 60 } my_grade = 70 if my_grade not in grades: z = 1 else: z = 2 if 'F' in grades: z = z + 10 else: z = z + 20

21

In Python, which of the following literals is shown in valid scientific notation?

3.0004e-12

What is the base 10 representation of the binary number: 00001001?

9

Which statement is true about the *args and **kwargs special arguments?

Both may be used in a single function call, but *args must appear before **kwargs in the argument list

Standard Python functions such as int(), range() etc. are part of the _____ scope.

Built-in

A programmer must write a program that lists all the words that appear in a text file that occur more than 10 times. Which of the following tasks would be a good first step in an incremental programming process?

Display the file's contents.

Which program can be used to create a Python file that can be used directly by the interpreter?

IDLE editor

Which of the following is not a valid technique to create a function stub?

Leave the function body empty

Which statement correctly explains a difference between lists and tuples?

List items can be changed, while tuple items can't be changed.

What is the output? def print_message1(): print('Message #1') def print_message2(): print('Message #2') print_message1 = print_message2 print_message2 = print_message1 print_message1() print_message2()

Message #2 Message #2

Which of the following is not one of the main scopes that Python uses to manage namespaces?

Namespace scope

_____ allows a function or operator to perform different tasks depending on the types of the arguments or operands.

Polymorphism

Which of the following types of constructs should be called when the programmer wants to stop program execution? You Answered

Raise NotImplementedError

RAM is an abbreviation that stands for:

Random Access Memory

If two variables with the same name exist in the Local scope and the Global scope, which variable will be used in an assignment statement?

The Local scope variable

What is Moore's Law?

The capacity of ICs doubles roughly every 18 months

What is the result when the program is executed? def add(x, y): return x + y print('Begin test') s = add('hello', 5) print(s) print('End test')

The program outputs 'Begin test', then an error is generated, and the program exits.

Which symbols are used to start and end a docstring?

Three quotation marks (""")

Which runtime error type occurs when trying to convert 'abc' to an integer? - LogicError - ValueError - NameError - TypeError

ValueError

Which X and Y cause the program to print the final velocity in feet per second? Note that the distance and initial_velocity are given using meters instead of feet.

X = meters_to_feet(v_i), Y = meters_to_feet(d)

What is the value of the __name__ built-in variable in a module that is executed as a script by the programmer?

__main__

What statement replaces XXX, causing the program to print the word 'hello'? def print_hello(): print('hello') XXX alternate()

alternate = print_hello

A sequence of instructions that solves a problem is called ______.

an algorithm

An item passed to a function is a(n) _____.

argument

In the following code, the variable val is the function call's _____. def calc_square_area(size): area = size * size return area val = float(input('Enter size of square: ')) square_area = calc_square_area(val) print(f'A square of size {val} has area {square_area}')

argument

Dictionaries are containers used to describe a(n) _____ relationship.

associative

0s and 1s are known as ___.

bits

What is a common word for the textual representation of a program?

code

Which of the following statements removes the value 'Google' from the set, companies? companies = { 'Apple', 'Microsoft', 'Google', 'Amazon' }

companies.remove('Google')

Which type of program converts a high-level language program into machine instructions?

compiler

The operator *= is called a(n) ____ operator.

compound

Which formatting presentation type is used to display an integer?

d

Which variable can be used in place of XXX in the following code? def fahrenheit_to_celsius(f): fraction = 5 / 9 c = (f - 32) * fraction return c degrees = float(input('Enter degrees in Fahrenheit: ')) print(fahrenheit_to_celsius(XXX))

degrees

Which statement removes entry "1G1JB6EH1E4159506" from the dictionary cars_dict?

del cars_dict["1G1JB6EH1E4159506"]

Which statement about Python is true? - Linux and Mac computers usually do not come with Python installed - there are no free web-based tools for learning Python - developers are not usually required to pay a fee to write a python program - windows usually comes with Python installed

developers are not usually required to pay a fee to write a python program

Which data type is the correct choice to store the number of wins associated with each basketball team in the NBA?

dict

The special two-item character sequence that represents special characters like \n is known as a(n) _____.

escape sequence

_____ is the process where objects that are no longer needed are deleted

garbage collection

The following program prints the number of integers in my_list that are greater than the previous integer in the list. Which choice fills in the blank to complete the for loop? my_list = [ 3, 2, 7, 8, 6, 9 ] count = 0 for _____: if my_list[i] > my_list[i-1]: count = count + 1 print(count)

i in range(1, len(my_list))

The built-in Python function that gives an object's identity is:

id()

A processor is a circuit that executes a list of _____.

instructions

A(n) ____ is a program that executes a script.

interpreter

A _____ can be located in a dictionary and is associated with a value.

key

A _____ is a word that is part of the Python language and can't be used as a variable name.

keyword

A(n) _____ is an example of a mutable object type.

list

Which data type is the correct choice to store a student's test scores in chronological order?

list

Which type of error does not cause the program to crash?

logic error

Which of the following assignment statements creates a list with 4 integer elements?

my_list = [7, 2, -8, 16]

Which statement removes the last element of my_list?

my_list.pop(len(my_list)-1)

What does print("one\\two\\\\three") display?

one\two\\three

The Python language is developed by a public community of users, therefore Python is a(n) ____ language.

open-source

The _____ is a process that manages programs and interfaces with peripherals.

operating system

Which operator is evaluated last in an expression?

or

Assigning a value to a floating point variable that is too large for the computer to represent is a condition called _____ .

overflow

Which statement is true regarding the pop() method for sets?

pop() removes a random item in the set.

Which print statement would display: I won't quit!

print('I won\'t quit!')

Which print statement would display the letter 'A'? (Note that the code for the letter 'A' is 65.)

print(chr(65))

Which print statement displays: 'Tokyo had 9.273000 million people in 2015'?

print(f'{"Tokyo":s} had {9.273:f} million people in {2015:d}')

Which print statement would display 'C:\Users\Mika\grades.txt' (without the single quotes)?

print(r'C:\Users\Mika\grades.txt')

Which function call would cause an error? def print_product(product_name, product_id, cost): print(f'{product_name} (id: #{product_id}) - ${cost:.2f}')

print_product('Speakers', 32.99, 21224)

What is an IDE used for?

program development, including writing the source code

Which statement, executed once, enables a program to generate the same sequence of pseudo-random numbers from random module methods each time the program is run?

random.seed(10)

Dividing by zero is an example of which type of error?

runtime

If text_line = 'one fish two fish', what is the value of text_line[6]?

s

The process of searching namespaces for a name is called _____.

scope resolution

Which data type is the correct choice to store the names of all the hockey players who have scored 3 or more goals in a single game in no specific order?

set

Which pair shows the correct classification of the given data type?

string, immutable sequence type

Which of the following statements produces an error? Assume string_1 = 'abc' and string_2 = '123'.

string_1[1] = 'B'

Which of the following data values is best represented with a floating point variable?

the speed of a snail

According to Python's precedence rules, which of the following operators has the highest precedence?

unary -

A ____ is a named item used to hold a value.

variable

Which expression is equivalent to the following code? if age < 18: x = x + 5 else: x = x + 1

x = x + 5 if age < 18 else x + 1

Which statement is equivalent to the following assignment? x -= 2 + y

x = x - (2 + y)

What values are in result_set after the following code is run? my_set = {1, 2, 3, 4, 5, 6} other_set = {2, 4, 6} result_set = my_set.union(other_set)

{1, 2, 3, 4, 5, 6}

What values are in result_set after the following code is run? my_set = {1, 2, 3, 4, 5, 6} other_set = {2, 4, 6} result_set = other_set.difference(my_set)

{}


Set pelajaran terkait

homework for econ exam 1, MICRO ECONOMICS, Chapter 2 (unit 1- obj. 10), Econ 1000 Chapter 3, 2.1-2.4, ECON Chapter 2 Homework, ECN101 Chapter 5 Key Terms, Econ 102 Exam, ECON102 CH. 4, 2.4 Gains from Trade, Microeconomics ch3, ECON E 201 Assignment 3...

View Set

Week 1-1-1 The TCP/IP Five-Layer Network Model

View Set

RCA 9.6 Practice Quiz Questions (Flash Cards)

View Set

Lecture 5-7: Intro to Neural Networks

View Set

Chapter 42: Drugs Used to Treat Glaucoma and Other Eye Disorders

View Set