PROGRAMMING FLASH CARDS

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

8) Which symbol is used in Python to create a comment?

#

Which code example is an expression? a. x = 4 b. print(x) c. (x * y) / 2 d. # Display x

(x*y) / 2

Which symbol represents the multiplication operation in programming

*

x = ? x = 15 x = x + 1 x = x * 2 x = 30 - x

-2

what displays empty_string = ''print(len(empty_string)

0

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

0-5

x = 0.3 z = math.pow(math.ceil(x), 2) what does z = ?

1.0

what is value of y? x = 10 y = x + 2 x = 12

12

a = 12 test_val = 6 if a * 2 == test_val: a = a + 7 else: test_val = 2 * a test_val = a + 1 value of test_val

13

what is output? id_list = [13, 984, 231, 140] for id in id_list: if id != 231: print(id, end=' ') else:print('Done')

13 984 140 done

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

17

day = 23 if day % 10 == 1: ending = "st" elif day % 10 == 2: ending = "nd" elif day % 10 == 3: ending = "rd" else: ending = "th" print(str(day) + ending)

23rd

Consider the following program:t = 15 t = t * 2 t = t + 1 t = t - 4 put t

27

my_list = [6, 2, 8, -1, 12, 15, -7] x = Get first my_list value While x is not negative put "Positive number!" to output x = Get next my_list value how many time will this loop execute?

3 times until first negative #

x = 7 If x < 7 x = x + 1 x = x + 2

9

) In Python, which of the following literals is shown in valid scientific notation? a. 3.0004e-12 b. 17.012s14 c. 0.003x10^-5 d. e12f3.04

A. 3.0004 e-12

Which of the following identifiers is valid a. max_age b. 32area c. transfer$ d. True

A. max age

With the logic block shown below, what is output when grade is assigned with thevalue 75?

B

According to Python's precedence rules, which of the following operators has the highest precedence A.subtraction - b. unary - c. * d. +

B. unary -

Which expression using parentheses is equivalent to the following expression :x - y * -z / 3 a. (x - y) * ((-z) / 3)) b. x - ((y * (-z)) / 3) c. x - (y * ((-z) / 3)) d. (x - (y * (-z))) / 3

B. x - ((Y * (-X)) / 3)

The operator *= is called a(n) _____ operator .a. double b. compound c. increment d. multiple assignment

B.compound

A language is called _____ when upper case letters in identifiers are considereddifferent from lower case letters

Case sensitive

what produces ERROR. string_2 = string_1 b. string_1 = string_2 + "456 "c. print(string_1 + string_2) d. string_1[1] = 'B'

D. string_1[1] = 'b'

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

Float

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

Keyword

10) Which statement outputs the text: "I won't quit!"?

NEEd double quatation bc puncuation print("I wont quit!"

Basic instruction types are input, process, and _____.a. output. b. memory C.calculationd. D.assigment

OUTPUT

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

One that ends with end = ' '

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

Prompt

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

S

Which runtime error type occurs when trying to convert 'abc' to an integer?

Value error

Space, tab, and newline are all called _____ characters

White space

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 what is z after this

Z = 21

names_list = ['one', 'two', 'three'] digits_list = ['1', '2', '3'] names_list = names_list + digits_list

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

Which print statement displays: 'Tokyo had 9.273000 million people in 2015'?a. print A.(f'{"Tokyo":s} had {9.273:f} million people in {2015:d}') b. print('{"Tokyo":s} had {9.273:f} million people in {2015:d}') c. print(f{"Tokyo":s} had {9273000:d} people in {2015:d}) d. print({"Tokyo":s} + ' had ' + {9.273:d} + ' million people in '+ {2015:d})

a. (f' Tokyo had 9

Given the following function. To change the function to return the product instead ofthe sum, how many lines of code need to be changed? def calculate(a, b): return a + b print(calculate(3, 4)) print(calculate(5, 2)) print(calculate(6, 7)) a. 1 b. 2 c. 3 d. 4

a. 1

Which floating-point literal correctly represents the scientific notation value: 2.3 x10^7 a. 2.3e7 b. 2.3*10e7 c. 2.3e10^7 d. 2.3xe7

a. 2.3e7

my_list = [3, 7, 0, 2, -1, 8] index = 0 while my_list[index] > 0: print(my_list[index], end=' ') index += 1 a. 3 7 b. 3 7 0 c. 3 7 0 2 d. 3 7 0 2 -1

a. 3 7

Which of the following assignment statements creates a list with 4 integer elements? a. my_list = [7, 2, -8, 16] b. my_list = [4] c. my_list = ['1', '2', '3', '4']

a. [7,2,-8,16)

Which statement uses the square() function to assign the variable t with 16? Notethat 16 = 2⁴ = (2²)² def calc_square(x): return x * x a. t = calc_square(calc_square(2)) b. t = calc_square(2) + calc_square(2) c. t = calc_square(2), calc_square(2) d. t = calc_square(4) * calc_square(2)

a. calc_square(calc_square(2))

Which determines if user_unit is in the list accepted_units?accepted_units = [ 'in', 'cm', 'mm', 'km', 'miles' ] a. if user_unit in accepted_units: b. if accepted_units in user_unit: c. if user_unit == (accepted_units): d. if user_unit == x in accepted_units

a. if user_unit in accepted_units:

Which of the following statements about my_list is false? my_list = ['JFK', 'LAX', 'MIA'] a. The element at index 1 is 'JFK' b. The list has a length of 3 c. The list elements are all strings d. The index of the last item in the list is 2

a. index at 1 is 'JFK'

Which of the following statements assigns a new variable, my_set, with a set thatcontains three elements? a. my_set = set([1, 2, 3]) b. my_set = set(3) c. my_set = [1, 2, 3].to_set() d. my_set = { [1, 2, 3] }

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

Which choice fills in the blank so that the output prints one line for each item insports_list, as in: 1. Hockey? sports_list = [ 'Hockey', 'Football', 'Cricket' ] for i in _____: print(f'{i+1}. {sports_list[i]}') a. range(len(sports_list)) b. range(len(sports_list-1) c. range(1, len(sports_list)) d. range(1, len(sports_list)-1)

a. range(len(sports_list))

What is the missing function name so that the output is: Cairo New York Paris Sydney? cities = ['Sydney', 'Paris', 'New York', 'Cairo']for c in _____(cities):print(c, end=' ') a. reversed b. backwards c. list d. inverse

a. reversed

Which statement assigns the string variable airport_code with the value JFK

airport_code = 'JFK'

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

Which of the following lines of code is not valid, given the definitions of thecalc_cube() and display() functions? def calc_cube(x): return x * x * x def display(x):print(x) a. y = calc_cube(2.0) b. calc_cube(x) = 8.0 c. display('Test') d. display(calc_cube(2.0))

b.

def reset(data): data[1] = 34 print(data) data = [15, 0, 47, 12, 0] reset(data) print(data) a. 34 [15, 0, 47, 12, 0] b. [15, 34, 47, 12, 0] [15, 34, 47, 12, 0] c. 34 [15, 34, 47, 12, 0] d. [15, 0, 47, 12, 0] [15, 0, 47, 12, 0]

b.

Which of the following statements has a syntax error? Assume age and years arevariables that have already been defined .a. age = years - 2 b. age + 2 = years c. age = 17 - 2 d. age = -15

b. age + 2 = years

Which formatting presentation type is used to display an integer? a. i b. d c. :d d.int

b. d

Which statement changes the value associated with key "Lemon" to 0.75 in thedictionary fruits_dict? a. fruits_dict[0.75] = "Lemon" b. fruits_dict["Lemon"] = 0.75 c. fruits_dict[Lemon] = 0.75 d. dict("Lemon") = fruits_dict[0.75]

b. fruits_dict["lemon"] = .75

Which statement removes the last element of my_list? a. my_list.pop(len(my_list)* b. my_list.pop(len(my_list)-1) c. my_list.remove(len(my_list)) d. my_list.remove(len(my_list)-1)

b. my_list.pop(len(my_list)-1)

Which statement has a syntax error? Assume variables x, y, z, and age have already been defined. a. y = y b. x + y = z c. age = '32'

b. x + y = z

Which of the following loops is best implemented with a while loop? a. Checking to see if a list of integers contains the value 12. b. Counting how many keys in a dictionary start with the letter 'A'. c. Asking the user to enter positive integers, exiting by entering -1. d. Looping through the characters in a string, and displaying 'yes' if it contains a vowel

c.

Which uses the concat() function to output: red fish blue fish? def concat(*args): s = '' for item in args: s += ' ' + item return s a. print(concat(['red, blue'], 'fish')) b. print(concat(red), concat(fish), concat(blue), concat(fish)) c. print(concat('red', 'fish', 'blue', 'fish')) d. print(concat(red, fish, blue, fish))

c.

what is output? for j in range(2): for k in range(4): if (k == 2): break print(f'{j}{k}', end=' ') a. 00 01 02 b. 00 01 02 03 c. 00 01 10 11 d. 00 01 02 10 11 12

c. 00 01 10 11

Which of the following is not a valid expression? Assume x and y are integervariables. a. x / (y * 7) b. y / x * 2* c. 2x + 3y d. (x - 3*y)

c. 2x + 3y

which calcs this .a^2 + b^2 a. math.square_root(a * a + b * b) b. math.sqrt(math.pow(a * a), math.pow(b * b)) c. math.sqrt(math.pow(a, 2) + math.pow(b, 2) d. math.pow(math.sqrt(a), 2) + math.pow(math.sqrt(b), 2)

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

Which statement prints the email address associated with thestudent id "C2104"

c. print(emails_dict["C2104"])

val = Get next input XXX While val is not -1 YYY val = Get next input Put sum to output a. sum = val / sum = val b. sum = val / sum = sum + val* c. sum = 0 / sum = sum + val d. sum = 0 / sum = val

c. sum = 0 / sum = sum + val

Which statement is equivalent to the following assignment?x -= 2 + y a. x = 2 + y - x b. x = -(2 + y) c. x = x - (2 + y) d. x = x - 2 + y

c. x = x - (2+y)

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

code

if color == 'red': if style < 3: print('A') elif style < 5: print('B') else: print('C') elif color == 'blue': print('D') what conditions displays 'B'

color == red and style is 4

Which of the following statements removes the value 'Google' from the set,companies?

companies.remove('google')

Which expression is equivalent to: not x and y == a and b? a. (not (x and y)) == (a and b) b. ((not x) and y) and (a and b) c. not ((x and (y == a)) and b) d. ((not x) and (y == a)) and b

d. ((not x ) and (y == a)) and b

Which formatting presentation type is used to display the integer 43 as 0X2b(hexadecimal in uppercase) a.h b. H c.x D. X

d. X

24) Which of the following symbols can be used as part of an identifier? @ $ & _

d. __

Which statement removes entry "1G1JB6EH1E4159506" from the dictionarycars_dict? a. cars_dict["1G1JB6EH1E4159506"] = None b. cars_dict{"1G1JB6EH1E4159506"}.del() c. delete(cars_dict["1G1JB6EH1E4159506"]) d. del cars_dict["1G1JB6EH1E4159506"]

d. del cars_dict[1G1JB6EH1E4159506"]

WHICH is correct. [principal x rate of interest] x time a. interest = [principal * rate_of_interest] * time b. interest = principal * rate of interest * time c. interest = principal x rate_of_interest x time d. interest = (principal * rate_of_interest) * time

d. interest = p * rateofInt) * time

Which of the following data values is best represented with a floating point variable a. The number of pets in a house. b. The number of acorns in a tree .c. The number of children in a classroom. d. The speed of a snail

d.SPEED OF SNAIL

Given x = 1, y = 2, and z = 3, how is the expression evaluated? In the choices, itemsin parentheses are evaluated first.(x == 5) or (y == 2) and (z == 5)

false or (true and false) >> false or false = false

A child is required to use a booster seat in a car until the child is 9 years old, unlessthe child reaches the height of 59 inches before age 9. Which expression can be used todecide if a child requires a car seat or not?

if child is >= 9 or height >=59

A company wants to send a reminder email to users who have not logged in formore than 10 days, but less than 20 days. Which expression can be used to decide if auser should get an email or not?

if days since log in > 10 and days since log in < 20

Which branch structure does a program use to output "Yes" if a variable's value ispositive, or "No" otherwise?

if- else (elif)

14) Which function converts a string to an integer?

int()

To quit, a user types 'q'. To continue, a user types any other key. Which expressionevaluates to true if a user should continue?

key != q

55) Which method call returns the number of elements in my_list?

len(my_list)

Which statement correctly explains a difference between lists and tuples?

lists can be changed , tuples cannot

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

logic error

my_name = input("Enter my name: ") your_name = input("Enter your name: ") if ZZZ: print("Same name") what should replace ZZZ to print same name

my_name == your_name

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

overflow

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

pop removes random item in a set.

7) Which instruction displays variables or expression values?

print()

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

random.randrange(7)

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

runtime

Given the named tupleFood = 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'(.2,14,1.3)

Fill in the blank so that the output is a count of how many negative values are intemperatures? temperatures = [-2, 8, 4, -7, 18, 3, -1] count = 0 for t in temperatures: if _____: count = count + 1 print(f'Total negative temperatures: {count}')

t < 0

Which symbols are used to start and end a docstring? a. One quotation mark (") b. Two quotation marks ("")* c. Three quotation marks (""") d. Four quotation marks ("""")

three quotation marks

Which statement reads a user-entered string into variable user_name? a. input = user_name() b. user_name = input() c. input() => user_name d. user_name = "input()

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 .a. output b. visibles c. variables d. instructions

variables

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

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

if age < 18: x = x + 5 else: x = x + 1 what is a statement that is equivalent using 1 line

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

Which expression for YYY will result in an output of "Pass" only if x is exactly 32?

x == 32

my_set = {1, 2, 3, 4, 5, 6}other_set = {2, 4, 6}result_set = my_set.union(other_set) what is in my set after this code.

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

my_set = {1, 2, 3, 4, 5, 6}other_set = {2, 4, 6}result_set = other_set.difference(my_set what values are in my set?

{}


Set pelajaran terkait

Advanced Organizational Behavior - Exam #4

View Set

Lista de nombres y su significado

View Set

Physical Science - Chapter 1 Reading Check Quiz

View Set

Product/Service Management (PM) Pre-test

View Set