TEST Flashcards

1
Q

\n digraph forces the print() function

A

Breaks the output line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Meaning of the keyword parameter

A

The argument’s name specified along with its value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The value twenty point twelve times ten raised to the power of eight should be written as?

A

20.12E8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The 0O prefix means that the number after it is denoted as.

A

Octal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The ** operator

A

Performs exponentiation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The result of the following division: 1/1

A

1.0 because the any time you use the divide by symbol it returns a floating point number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If you wanted to return 1

A

you would use 1 // 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The result of the / operator is always an integer value

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

the result of the following expression:
1 // 2 * 3
zero -

floor division // ***

A

Left sided binding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

variable names are illegal

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The print() function can output values of
any number of arguments

A

(including zero)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Output of the following snippet
x=1
y=2
z=x (1)
x=y (2)
y=z (1)
print(x,y)

A

2 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the output of the following snippet if the user enters two lines containing 2 and 4

x=input() 2
y=input() 4
print(x+y)

A

input always inputs string so it would need int if it wanted to be converted to integer so the output is.
24

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the output of the following snippet if the user enters the two lines 2 and 4

x=int(input) 2
y=int(input) 4
x=x//y 0 2 floor division 4
y=y//x 4 / 0
print(y)

A

code will cause a runtime error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the output of the following snippent if user enters 2 and 4?

x=int(input()) .5
y=int(input()) 4
x=x/y
y=y/x
print(y)

A

8.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the output of the following snippet if the user enters two lines containing 11 and 4.

x=int(input())
y=int(input())
x = x % y 3
x = x % y 3 3 mod 4 is still 3
y = y % x 4 mod 3 == 1
print(y)

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the output of the following snippet if the user enters two lines containing 3 and 6.
x=input() string 3
y=int(input() 6
print(x*y)

A

outputs 333333

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the output of the following snippet
z = y = x = 1
print(x,y,z,sep=’*’)

A

111

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Output of the following snippet
x = 2 + 3 * 5.
print(X)

A

17.0

***Causes execution error because the variable X is never created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the output of the following snippet
x = 1 / 2 + 3 // 3 + 4 ** 2
print(x)

4 ** 2 = 16
3 floor division 3 == 1 17
1 / 2 = .5

A

17.5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the output of the following snippet if the user enters two lines containing 2 and 4

x=int(input())  2
y=int(input())  4
print(x+y)      6
A

6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

An operator able to check whether two values are equal is

A

’==’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

The value eventually assigned to x is equal to:

x = 1
x = x == x

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How many stars will the following snippet send to the console.

i = 0
while i <= 3 :
i += 2
print(“*”)

A

2 stars are output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How many stars will the following snippet send to the console.

i = 0
while i <= 5 :
i += 1
if i % 2 == 0:
break
print(“*”)

A

Only prints 1 stars

26
Q

How many hashes will the following snippets send to the console?
for i in range(1):
print(“#”)
else:
print(“#”)

A

prints 2 hashes

27
Q

How many hashes will the following snippet send to the console?
var = 0
while var < 6:
var += 1
if var % 2 == 0:
continue
print(“#”)

A

3 hases

28
Q

How many hases will the following snippet send to the console.

var = 1
while var < 10:
print(“#”)
var = var &laquo_space;1 (need to look up bitwise operators)

A

stop at 4 hashes

29
Q

What value will be assigned to the x variable?
z = 10
y = 0
x = y < z and z > y or y > z and z < y

and comes before or

A

T T True because

30
Q

Output of the following snippet
a = 1
b = 0
c = a & b bitwise operator - bits 0000 and 0001
d = a | b = 1 in terms of bits
e = a ^ b = 1
print (c + d + e)

A

2

31
Q

Output of the following snippet

lst = [3, 1, -2]
print(lst[lst[-1]])

A

1

32
Q

Output?

lst = [1,2,3,4]
print(lst[-3:-2])

A

[2]

33
Q

Output

vals = [0, 1, 2]
vals[0], vals[2] = vals[2], vals[0]

A

reverses the list

34
Q

After execution of the following snippet the sume of all vals elements will be equal to

vals = [0, 1, 2]
vals.insert(0,1)
del vals[1]

A

4

35
Q

What is true

nums = [1,2,3]
vals = nums
del vals[1:2]

A

nums and vals are the same length

36
Q

what is true
numbs = [1,2,3]
vals = nums

A

del vals[1:2]

37
Q

What is true

nums = [1,2,3] = 1 2 3
vals = nums[-1:-2] all the way to -1 but not including -2

A

nums is longer than vals

38
Q

What is the output

|1 = [1,2,3]
|2 = []
for v in |1:
|2.insert(0,v)
print(|2)

v is zero

A

[3,2,1]

39
Q

What is the output of the following snippet
|1 = [1,2,3]
for v in range(len(|1)):
|1.insert(1,|1[v])
print(|1)

A

[1, 1, 1, 1, 2, 3]

40
Q

How many elements does the L list contain?

L = [i for i in range(-1,2)]

A

3 -1, 0, 1

41
Q

What is the output of the following snippet

T = [[3-i for i in range (3)] for j in range (3)]
s = 0
for i in range(3):
s += T[i][i]
print(s)

A

6

42
Q

What is the output

L = [[0, 1, 2, 3] for i in range(2)]
print(L[2][0])

A

snippet will cause a runtime error

43
Q

Properly starts a parameterless function definition.

A

def fun():

44
Q

A function defined in the following way

def function(x=0):
return x*y

A

may be invoked without any argument, or with just one.

45
Q

a function that
Comes with Python and is an integral part of python

A

built in function

46
Q

The fact that tuples belong to the sequence types means

A

They can be indexed and sliced like lists.

47
Q

output?

def f(x):
if x == 0:
return 0
return x + f(x - 1)

print(f(3))

A

6

48
Q

Output?

def fun(x):
x += 1
return x

x = 2
x = fun(x+1)
print(x)

A

4

49
Q

what can you insert into commented line to obtain the output that reads

a
b
c

Code:

dct = {}
lst = [‘a’,’b’,’c’,’d’]
for i in range(len(lst) - 1):
dct[lst[i]] = ( lst[i], )
for i in sorted(dct.keys()):
k = dct[i]
# insert code here

A

print(k[0])

50
Q

The following snippet
def func(a,b):
return a ** a
print(func(2)

A

Causes an error

51
Q

Snippet

def func1(a):
return a ** a
def func2(a):
return func1(a)*func1(a)
print(func2(2))

A

will output 16

52
Q

Which of the following lines properly starts a function using two parameters, both with zeroed default values?

A

def fun(a=0,b=0):

53
Q

None value may not be used outside functions

A

False

54
Q

Output of following
def fun(x):
if x % 2 == 0:
return 1
else:
return

print(fun(fun(2)) + 1)

A

The code will cause a runtime error

55
Q

Output of the following
def fun(x):
global y
y = x * x
return y

fun(2)
print(y)

A

Returns 4

56
Q

Output of the following

def any():
print(var + 1,end=”)
var = 1
any()
print(var)

A

21

57
Q

Assuming that tuple is a correctly created tuple, the fact that tupples are immutable means that the following instruction is
tuple[1] = tuple[1] + tuple[0]

A

illegal because you can not change value of the tuples

58
Q

Output

list = [‘Mary’, ‘had’, ‘a’, ‘little’, ‘lamb’]
def list(L):
del L[3]
L[3] = ‘ram’
print(list(list))

A

snippet is errorneous

59
Q

Output of the following snippet

def fun(x,y,z)
return x+2y+3zero

print(fun(0,z=1,y=3))

A

9

60
Q

Output

def fun(inp=2,out=3):
return inp * out
print(fun(out=2))

A

4

61
Q

Output

dct = { ‘one’:’two’, ‘three’:’one’, ‘two’:’three’ }
v = dct[‘one’]
for k in range(len(dct)):
v = dct[v]
print(v)

A

two

62
Q

Output of snippet

tup = (1, 2, 4, 8)
tup = tup[1:-1]
tup = tup[0]
print(tup)

A

2