CSCE 110 Midterm

Ace your homework & exams now with Quizwiz!

functions

range() and main() are considered these in python

5, 6, 7, 8, 9

range(5,10) returns what?

immutable

tuples are mutable/immutable

==

Which operator can be used to compare two values?

T

T/F The 'in' operator is used to check if a value exists within an iterable object container such as a list. Evaluates to true if it finds a variable in the specified sequence and false otherwise.

{2, 3}

what is the output of this intersection: a = {1,2,3} b = {2,3,4} a & b

{1, 2, 3, 'c', 'b', 'a'}

what is the output of this union: a = {1,2,3} b = {'a', 'b', 'c'} a | b

yes

Can lists have heterogenous elements? ex: ['dog', 78]

yn

What is the output of the following code? str = "pynative" print (str[1:3])

J,h,o,n

What is the output of the following loop: for l in 'Jhon': if l == 'o': pass print(l, end=", ")

9.0

What is the value of the following Python Expression: print(36 / 4)

(3,4)

What will be the output of the following Python code? p = (2,3,4,5) p[1:-1]

(3,5,4)

What will be the output of the following Python code? p = (2,3,5,4) p[1:4]

[2,5,8]

What will be the output of the following Python code? p = (2,3,5,4,8,9) [p[y] for y in range(0, len(p), 2)]

('apple', 'mango')

What will be the output of the following Python code? x1 = ('apple',) x2 = ('mango',) x3 = x1 + x2 print(x3) (apple, mango) ('apple', 'mango') ('apple''mango') None

set

Which collection does not allow duplicate members? set list tuple

replace()

Which method can be used to replace parts of a string?

<class 'dict'>

axa = {} print(type(axa)) What gets printed? <class 'set'> <class 'dict'> <class 'list'>

element

in the list ['hello', 78], hello and 78 are called this.

docstring

optional comments are called this '''Hello'''

Concatenates string1 and string2

What does the expression string1 + string2 do? Repeats string1 string2 times (string2 must be in numeric format). Concatenates string1 and string2. It's a syntax error. Adds string1 to string2 (both must be in numeric format).

Error

What gets printed? p = 'abb' q = 2 print(p+q)

print('Hello World')

What is a correct syntax to output "Hello World" in Python?

x = "Hello"[0]

What is a correct syntax to return the first character in a string? x = "Hello"[0] x = sub("Hello", 0, 1) x = "Hello".sub(0, 1)

[11, 15, 19]

What is output for: b = [11,13,15,17,19,21] ptint(b[::2])

print(type(x))

What is the correct syntax to output the type of a variable or object in Python?

def myFunction():

What is the correct way to create a function in Python?

int

What is the data type of (1)?

sets are unordered and unindexed, dictionaries are ordered and mutable

What is the difference between sets and dictionaries?

True

What is the output of print 0.2 + 0.3 == 0.5

2

What is the output of print(2%6) ValueError 0.33 2

PYnative // is for // Python Lovers//

What is the output of the following code print('PYnative ', end='//') print(' is for ', end='//') print(' Python Lovers', end='//')

25 50

What is the output of the following code x = 50 def fun1(): x = 25 print(x) fun1() print(x)

syntax error

What is the output of the following code: sampleSet = {"Yellow", "Orange", "Black"} print(sampleSet[1]) Yellow Syntax Error Orange

50

What is the output of the following code: x = 100 y = 50 print(x and y)

75

What is the output of the following code? a = 75 def var_test(): return a print(var_test())

63

What is the output of the following code? def var_test(): b = 63 return b print(var_test())

10, 11, 12, 13, 14,

What is the output of the following code? for i in range(10, 15, 1): print( i, end=', ')

The program executed with error (The set is an unordered data structure. So you cannot access/add/remove its elements by index number.)

What is the output of the following code? sampleSet = {"Jodi", "Eric", "Garry"} sampleSet.add(1, "Vicki") print(sampleSet) {'Vicki', 'Jodi', 'Garry', 'Eric'} {'Jodi', 'Vicki', 'Garry', 'Eric'} The program executed with error

maJ

What is the output of the following code? var= "James Bond" print(var[2::-1])

15

What is the output of the following code? xx = 15 def var_test(): xx = 25 var_test() print(xx)

25

What is the output of the following code? xx = 15 if True: xx = 25 print(xx)

100

What is the output of the following code? xx = 50 def var_test(): xx = 100 return xx print(var_test())

-2, -3, -4

What is the output of the following for loop and range() function: for num in range(-2,-5,-1): print(num, end=", ")

Emma 25

What is the output of the following function call: def fun1(name, age=20): print(name, age) fun1('Emma', 25)

10 11 12 13

What is the output of the following nested loop: for num in range(10, 14): for i in range(2, num): if num%i == 1: print(num) break

10 Chair 10 Table 20 Chair 20 Table

What is the output of the following nested loop? numbers = [10, 20] items = ["Chair", "Table"] for x in numbers: for y in items: print(x, y)

['b','e']

What is the output of the following program? a = list('abcdefg') print(a[1::3])

2, 1, 0, -1, -2, -3, -4

What is the output of the following range() function: for num in range(2,-5,-1): print(num, end=", ") ans choices: 2, 1, 0 2, 1, 0, -1, -2, -3, -4, -5 2, 1, 0, -1, -2, -3, -4

0.0

What is the result of round(0.5) - round(-0.5)? 1.0 2.0 0.0

90

What is the value of x after the following nested for loop completes its execution? x = 0 for i in range(10): for j in range(-1, -10, -1): x += 1 print(x)

100

What is the value of x: x = 0 while (x < 100): x+=2 print(x)

dictionary

What is this called? {"name": "apple", "color": "green"}

f

What will be the output of the following Python code? alpha = ('a', 'g', 'f') print(alpha[-1])

g

What will be the output of the following Python code? alpha = ('a', 'g', 'f') print(alpha[1])

45

What will be the output of the following Python code? d = {'jimmy':45, 'jack':40} d['jimmy']

3

What will be the output of the following Python code? fruit = ('apple', 'orange', 'apple', 'cherry', 'apple') print(fruit.count('apple'))

Error as tuple is immutable

What will be the output of the following Python code? x - (5,6,7,8) del(x[2]) Now, a=(1,2,4) Now, a=(1,3,4) Now a=(3,4) Error as tuple is immutable

('CheckCheckCheck')

What will be the output of the following Python code? x = ('Check') * 3

(2,3,4,5)

What will be the output of the following Python code? x = (2,3) y = (4,5) z = x+y z

(8,6)

What will be the output of the following Python code? x,y - 6,8 x,y = y,x x,y

(2,3,2,3)

What will be the output of the following Python code? p = (2,3) p * 2

list

Which collection is ordered, changeable, and allows duplicate members? set list dictionary tuple

strip()

Which method can be used to remove any whitespace from both the beginning and the end of a string?

upper()

Which method can be used to return a string in upper case letters?

route66, Age, home_address

Which of the following are valid Python variable names: route66 4square ver1.3 Age home_address return

x y z = 1 2 3

Which of the following is an invalid statement? num = 1,000,000 x y z = 1 2 3 x,y,z = 1, 2, 3 x_y_z = 1,000,000

*

Which of the following operators has the highest precedence? not & * +

my-var

Which one is NOT a legal variable name? my-var Myvar my_var _myvar

**

Which operator has higher precedence in the following list % (Modulus) & (BitWise AND) ** (Exponent) > (Comparison)

break

Which statement is used to stop a loop?

T

T/F Python syntax is case-sensitive.

T

T/F The first character of a variable in Python can be a letter or an underscore.

F

T/F We can use the float numbers in range() function.

T

T/F When A is a set, A >= A

F

T/F When a is a set, a < a

True False

What is the output of the following code? listOne = [20, 40, 60, 80] listTwo = [20, 40, 60, 80] print(listOne == listTwo) print(listOne is listTwo)

10 20 30

What is the output of the following code? p, q, r = 10, 20 ,30 print(p, q, r)

<class 'function'>

What is the output of the following code? print(type(lambda:None)) <class 'type'> <class 'function'> <class 'bool'>

0, 1

For splicing x[a:b:c]: if a is missing, the value is ___ if c is missing, the value is __ if b is missing, the value is the length of the string.

3

Given the nested if-else below, what will be the value x when the code executed successfully: x = 0 a = 5 b = 5 if a > 0: if b < 0: x = x + 5 elif a > 5: x = x + 4 else: x = x + 3 else: x = x + 2 print(x)

[x,y]

If x and y are strings, which of the following is equivalent to [x] + [y] ? [x].extend([y]) [x,y] [x + y] [x].append(y)

for, while

Use a for/while loop when you know exactly how many times a loop needs to run, and a for/while loop when you can't predict how often it repeats

string, list, tuple, set, dictionary (NOT int, float, bool)

data types in python that are iterables

T

T/F In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type.

F

T/F In Python, a variable must be declared before it is assigned a value.

T

T/F In Python3, Whatever you enter as input, the input() function converts it into a string

F

T/F In order to execute an operation over arguments of different data types, convert all of them to the same type beforehand.

F

T/F Only immutable data types can be used as keys for dictionaries in Python.

T

T/F Python function always returns a value

brackets, parentheses, squiggly braces,

What are each of the following data structures inclosed in: lists tuples dictionaries and sets

2

Given the nested if-else structure below, what will be the value of x after code execution completes: x = 0 a = 0 b = -5 if a > 0: if b < 0: x = x + 5 elif a > 5: x = x + 4 else: x = x + 3 else: x = x + 2 print(x)

(2,3)

If x=(1,2,3,4), x[1:-1] is _________

ductionary

In order to store values in terms of key and value which core data type is used.

string, tuple, range, integer, float, Boolean

List the data types in python that are IMMUTABLE

list, dictionary, set

List the data types in python that are MUTABLE

parentheses, index (slicing), exponent, multiplication/division/modulus, add and subtract, comparisons, Boolean (not, and, then or)

Order of operations in python

A, B

Select which is true for for loop: A. Python's for loop used to iterates over the items of list, tuple, dictionary, set, or string B. else clause of for loop is executed when the loop terminates naturally C. else clause of for loop is executed when the loop terminates abruptly D. We use for loop when we want to perform a task indefinitely until a particular condition is met

T

T/F In Python if a variable is assigned a value anywhere within the function's body, it's assumed to be a local unless explicitly declared as global.

T

T/F In Python, 'Hello', is the same as "Hello"


Related study sets

Network + Guide To Network Chapter 8 , 8 edition

View Set

CHAPTER 23 CHEMICAL & WASTE MANGEMENT

View Set

General Anatomy and Radiographic Positioning Terminology, Chapter 3

View Set

Chapter 4: Socialization and the Life Course - InQuizitive Answers

View Set

Airway, Respiration, and Ventilation - EMTPREP

View Set