CSC 115 Midterm

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

Which symbol can be used as part of an identifier?

"_" (underscore)

Which symbol is used in Python to create a comment?

#

15 _____ 3 = 0

%

Which expression calculates the average of first_num and second_num?first_num = input('Enter the first number: ') second_num = input('Enter the second number: ')

(float(first_num) + float(second_num)) / 2

What is an example of a code expression?

(x * y) / 2

Which symbol represents the multiplication operation in programming?

*

What is the value of x after the following code is executed? x = 15 —> x = x + 1 —> x = x * 2 —> x = 30 - x

-2

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

-4...4

15 _____ 3 = 5.0

/

What is displayed when the following code is executed? empty_string = ' ' print(len(empty_string))

0

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

0...5

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

00001100

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

00100011

What is the ending value of z? x = 0.3 z = math.pow(math.ceil(x), 2)

1.0

What is the value of y after the following code is executed? x = 10 —> y = x + 2 —> x = 12

12

my_list = [2, 8, 3, 1, 18, 5] print(my_list[3] + my_list[1] * 2)

17

A computer processor stores numbers using a base of _____.

2

Which floating-point literal correctly represents the scientific notation value: 2.3 x 10^7?

2.3e7

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

2.5

Consider the following program: t = 15 —> t = t * 2 —> t = t + 1 —> t = t - 4 —> what is the output of t?

27

Which of the following is not a valid expression? Assume x and y are integer variables.

2x + 3y

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: 00101110?

46

What is the value of 11 // 2?

5

Which of the following expressions causes an implicit conversion between types? Assume variable x is an integer, t is a float, and name is a string.

7.5 + (x / 2)

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

9

What is the result of the expression: int('1750.0')?

An error: the string does not represent an integer value

Which statement about Python is true?

Developers are not usually required to pay a fee to write a Python program.

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

IDLE editor

What is an IDE used for?

Program development, including writing the source code.

Which of the following statements about my_list is false? my_list = ['JFK', 'LAX', 'MIA']

The element at index 1 is 'JFK'

Which formatting presentation type is used to display the integer 43 as 0X2b (hexadecimal in uppercase)?

X

What are the contents of names_list after the following code is executed? names_list = ['one', 'two', 'three'] digits_list = ['1', '2', '3'] names_list = names_list + digits_list

['one', 'two', 'three', '1', '2', '3']

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

__main__

Which of the following statements has a syntax error? Assume age and years are variables that have already been defined.

age + 2 = years

Which statement assigns the string variable airport_code with the value JFK?

airport_code = 'JFK'

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

an algorithm

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

argument

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

associative

A language is called _____ when upper case letters in identifiers are considered different from lower case letters.

case sensitive

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

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

compound

Which formatting presentation type is used to display an integer?

d

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

del cars_dict["1G1JB6EH1E4159506"]

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

What is the name of the data type used for floating point numbers?

float

Which statement changes the value associated with key "Lemon" to 0.75 in the dictionary fruits_dict?

fruits_dict["Lemon"] = 0.75

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

garbage collection

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

id()

Objects like integers and strings that can't be modified are called _____ .

immutable

Which statement makes the code in the math module available?

import math

Which function converts a string to an integer?

int()

The formula for calculating the amount of interest charged on a loan is: interest = [principal x rate of interest] x time Which Python statement correctly performs the interest calculation?

interest = (principal * rate_of_interest) * time

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

Which method call returns the number of elements in my_list?

len(my_list)

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

list

Which statement correctly explains a difference between lists and tuples?

list items can be changed, while tuple items can't be changed

Assume a and b are variables that hold the base and height of a right triangle. The length of the long side (hypotenuse) is calculated as the square root of a^2 + b^2. Which expression calculates the length of the hypotenuse?

math.sqrt(math.pow(a, 2) + math.pow(b, 2))

Which of the following identifiers is valid?

max_age

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)

Which of the following statements assigns a new variable, my_set, with a set that contains three elements?

my_set = set([1, 2, 3])

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

one\two\\three

Basic instruction types are input, process, and _____.

output

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 statement outputs the text: "I won't quit!"?

print("I won't quit!")

Which statement does not print a newline character at the end?

print('First part...', end='')

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

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

Which instruction displays variables or expression values?

print()

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

print(chr(65))

The variable emails_dict is assigned with a dictionary that associates student ids with email addresses. Which statement prints the email address associated with the student id "C2104"?

print(emails_dict["C2104"])

Which line in the following program causes a runtime error? sales = { "apples": 0, "lemonade": 0 } sales["apples"] = sales["apples"] + 1 del sales["lemonade"] print(len(sales["apples"]))

print(len(sales["apples"]))

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

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

Which print statement displays the value of a variable called argv in a module called sys?

print(sys.argv)

In the statement: age = input('Enter your age: ') , the string 'Enter your age: ' is called a(n) _____.

prompt

Dice have 6 sides, with values 1, 2, 3, 4, 5, and 6. Which expression randomly rolls one dice, directly yielding one of those values?

random.randint(1, 6)

Which generates a random integer in the range 13...19 (inclusive)?

random.randrange(19 - 13 + 1) + 13

Which expression is most appropriate for randomly choosing a day of the week?

random.randrange(7)

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)

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)

result_set = { }

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

s (whitespaces count)

Which expression gives the number of whole minutes that corresponds to some number of seconds?

seconds // 60

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

Given the named tuple Food = namedtuple('Food', ['name', 'fat', 'carbs', 'protein']), create a new Food tuple called snack where snack.name is 'apple', snack.fat is 0.2, snack.carbs is 14, and snacks.protein is 1.3.

snack = Food('apple', 0.2, 14, 1.3)

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 -

Which statement reads a user-entered string into the variable user_name?

user_name = input()

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

variable

In an instruction like: z = x + y, the symbols x, y, and z are examples of _____.

variables

Which statement correctly creates a new tuple west_cities with elements 'Vancouver', 'Portland', 'Eugene' in that order?

west_cities = ('Vancouver', 'Portland', 'Eugene')

Space, tab, and newline are all called _____ characters.

whitespace

Which expression using parentheses is equivalent to the following expression: x - y * -z / 3

x - ((y * (-z)) / 3)

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}


Kaugnay na mga set ng pag-aaral

Ch 1- Intro to Accounting and Financial Reporting for Governmental and Not-for-Profit Organizations, Ch2 - Overview of Financial Reporting for State and Local Governments, Ch 3- Modified Accrual Accounting, Chapter 4 MCQ, Ch. 5 | Government and Not F...

View Set

Quiz 6: JavaScript 3 and the DOM

View Set

Human Growth and Development module 8

View Set

Marketing Midterm Practice Questions

View Set

Adjective suffixes - ive, -y, -ous, -ful,- less, -able, -ible, -al

View Set