Computer Science Chapter 2-4

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

How do you access strings?

{ }

What is the output? set_a = {1, 2, 3} set_b = {2, 3, 4} set_a.symmetric_differences(set_b)

{1, 4}

Add parentheses to the following: not x and y == a and b

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

What operator is evaluated first: x + y < y - z * 2?

*

Input: sales_type = 2 sales_bonus = 3 if sales_type == 2: if sales_bonus < 5: sales_bonus = 10 else: sales_bonus = sales_bonus + 1 print(sales_bonus)

10

What is the output? a = 12 tes_val = 6 if a * 2 == test_val: a = a + 7 else: test_val = 2 * a test_val = a + 1

13

What is the x's final value? x = 10 y = 20 if y <= x * 2: x = x + 5 else: x * 2

15

What is the output? my_list = [2 8 3 1 18 5] print(my_list[3] + my_list[1] * 2

17

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

2.5

What kind of data type is this? players = {'Lionel Messi; : 10, 'Cristiano Ronaldo' : 7} Is it immutable?

Dictionary, mutable (keys, however, are not mutable)

True or False: When creating a list, integers can be placed inside quotation marks.

False

True or False: my_set = set {[1, 2, 3]} correctly assigns my_set to a set with a list of 3 elements.

False

Given x = 1, y = 2, z = 3, how is the expression evaluated? (x == 5) or (y == 2) and (z ==5)

False or (True and False) False or False False

What is the name of the element at index 1 in my_list = ['JFK', 'LAX', 'MIA']?

LAX

What kind of data type is this? my_num = [1, 2, 3, 4, 5] Is it mutable?

List, mutable

Which data types are mutable?

Lists, sets, and dictionaries

Which operator is evaluated last in any expression?

Or

What are the precedence rules when including the inequalities and the not/and/or statements?

Parentheses, unary, multiplication/division, addition/subtraction, inequality statements, not, and , or

What does set.difference do?

Returns a new set containing on the elements of a certain set that aren't found anywhere else.

What does set.union do?

Returns a new set containing the elements in all sets combined. If an element appears twice, the duplicate is removed.

What does set_a.symmetric_differences(set_b) do?

Returns a new set with values in either A OR B. If an element appears in both, that is not included in the output.

What does set.intersection do?

Returns the common elements that show up in all provided sets

What kind of data type is this? user_input = ['one', 'two', 'three'] Is it mutable?

Set, mutable

What kind of data type is this? user_input = ('Spelman is in Atlanta') Is it mutable?

String, immutable

What data types are immutable?

Strings, tuples

Which is true of the badly formatted code? x = input() if x == 'a': print('first') print('second')

The first print statement must be indented

numbers = (0, 1, 2, 3) Is it mutable?

Tuple, immutable

How do you access dictionary entries, lists, sets, and tuples?

[ ]

What is the proper statement to write to check if user_input is in the list accepted_units? accepted_units = ['in', 'cm', 'mm', 'km', 'miles']

if user_input in accepted_units:

What statement allows for a user to remove the last element in a list?

list.pop

What condition should be used to replace ZZZ to output "Same name" only if the two variables are the same? my_name = input('Enter my name: ') your_name = input('Enter your name: ') if ZZZ: print('Same name')

my_name == your_name

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

s


Ensembles d'études connexes

Safety in Academic Chemistry Laboratories

View Set

EW 2 Unit 12 p 120 предлоги движения

View Set

Chapter 4: Life Insurance Policies

View Set