TEST Flashcards

(62 cards)

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
How many stars will the following snippet send to the console. i = 0 while i <= 5 : i += 1 if i % 2 == 0: break print("*")
Only prints 1 stars
26
How many hashes will the following snippets send to the console? for i in range(1): print("#") else: print("#")
prints 2 hashes
27
How many hashes will the following snippet send to the console? var = 0 while var < 6: var += 1 if var % 2 == 0: continue print("#")
3 hases
28
How many hases will the following snippet send to the console. var = 1 while var < 10: print("#") var = var << 1 (need to look up bitwise operators)
stop at 4 hashes
29
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
T T True because
30
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)
2
31
Output of the following snippet lst = [3, 1, -2] print(lst[lst[-1]])
1
32
Output? lst = [1,2,3,4] print(lst[-3:-2])
[2]
33
Output vals = [0, 1, 2] vals[0], vals[2] = vals[2], vals[0]
reverses the list
34
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]
4
35
What is true nums = [1,2,3] vals = nums del vals[1:2]
nums and vals are the same length
36
what is true numbs = [1,2,3] vals = nums
del vals[1:2]
37
What is true nums = [1,2,3] = 1 2 3 vals = nums[-1:-2] all the way to -1 but not including -2
nums is longer than vals
38
What is the output |1 = [1,2,3] |2 = [] for v in |1: |2.insert(0,v) print(|2) v is zero
[3,2,1]
39
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)
[1, 1, 1, 1, 2, 3]
40
How many elements does the L list contain? L = [i for i in range(-1,2)]
3 -1, 0, 1
41
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)
6
42
What is the output L = [[0, 1, 2, 3] for i in range(2)] print(L[2][0])
snippet will cause a runtime error
43
Properly starts a parameterless function definition.
def fun():
44
A function defined in the following way def function(x=0): return x*y
may be invoked without any argument, or with just one.
45
a function that Comes with Python and is an integral part of python
built in function
46
The fact that tuples belong to the sequence types means
They can be indexed and sliced like lists.
47
output? def f(x): if x == 0: return 0 return x + f(x - 1) print(f(3))
6
48
Output? def fun(x): x += 1 return x x = 2 x = fun(x+1) print(x)
4
49
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
print(k[0])
50
The following snippet def func(a,b): return a ** a print(func(2)
Causes an error
51
Snippet def func1(a): return a ** a def func2(a): return func1(a)*func1(a) print(func2(2))
will output 16
52
Which of the following lines properly starts a function using two parameters, both with zeroed default values?
def fun(a=0,b=0):
53
None value may not be used outside functions
False
54
Output of following def fun(x): if x % 2 == 0: return 1 else: return print(fun(fun(2)) + 1)
The code will cause a runtime error
55
Output of the following def fun(x): global y y = x * x return y fun(2) print(y)
Returns 4
56
Output of the following def any(): print(var + 1,end=") var = 1 any() print(var)
21
57
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]
illegal because you can not change value of the tuples
58
Output list = ['Mary', 'had', 'a', 'little', 'lamb'] def list(L): del L[3] L[3] = 'ram' print(list(list))
snippet is errorneous
59
Output of the following snippet def fun(x,y,z) return x+2*y+3*zero print(fun(0,z=1,y=3))
9
60
Output def fun(inp=2,out=3): return inp * out print(fun(out=2))
4
61
Output dct = { 'one':'two', 'three':'one', 'two':'three' } v = dct['one'] for k in range(len(dct)): v = dct[v] print(v)
two
62
Output of snippet tup = (1, 2, 4, 8) tup = tup[1:-1] tup = tup[0] print(tup)
2