Structured Programming (Python) Flashcards

1
Q

Python can be easily integrated to C++, DOM, Active X and COBRA. (T/F)

A

FALSE* (COM*)

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

*Python is _____________ application.

A

INTERPRETED

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

Python uses curly brackets like C, C++ and Java to denote delimit blocks. (T/F)

A

FALSE, WHITESPACES

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

Python version 3.6 was release 2015. (T/F)

A

FALSE, 2016 (Dec. 22)

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

Python version 3.5 was release 2014. (T/F)

A

FALSE, 2015 (Sep. 12)

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

Python uses duck typing and has typed objects but untyped variable names. (T/F)

A

TRUE

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

Python has fewer ________ constructions than other languages.

A

SYNTACTICAL

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

It uses ________ keywords frequently whereas the other languages use punctuations.

A

ENGLISH

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

Python can run on a wide variety of hardware platforms and has the same interface on all platforms. (T/F)

A

TRUE

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

Python is similar to the following PL _____________.

A

JAVA AND C

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

All keywords in Python are in _________.

A

NONE OF THE MENTONED

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

What is the answer to this expression, 22 % 3 is?

A

1

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

Which of the following is not a keyword?
Group of answer choices

assert

nonlocal

pass

eval

A

EVAL

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

What is the maximum possible length of an identifier?

A

ANY LENGTH

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

Operators with the same precedence are evaluated in which manner?

A

LEFT TO RIGHT

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

Mathematical operations can be performed on a string. (T/F)

A

FALSE

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

There are how many keywords in Python 3.x interpreter.

A

33

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

> > > symbol is knows as.

A

(Python) Interactive Shell

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

What is the order of precedence in python? i) Parentheses ii) Exponential iii) Multiplication iv) Division v) Addition vi) Subtraction

A

i,ii,iii,iv,v,vi

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

Which one of the following has the highest precedence in the expression?
Group of answer choices

Addition

Multiplication

Exponential

Parenthesis

A

Parenthesis

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

The syntax of methods is instance.method(Object). (T/F)

A

FALSE, instance.method(argument)

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

Python version 3.4 was release March 2014. (T/F)

A

TRUE

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

Unnamed functions are implemented using lambda expressions (T/F)

A

TRUE

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

Python does not allow chained comparison. (T/F)

A

FALSE, DOES ALLOW

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

Python’s bulk of the library is very portable and cross-platform compatible on UNIX, Windows, and Macintosh. (T/F)

A

TRUE

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

Python allows programmer to define their own type using def function, which are not use for object-oriented programming. (T/F)

A

FALSE, “Python allows programmers to define their own types
using classes, which are most often used for object-oriented
programming.”

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

Which of the following is an invalid variable?
Group of answer choices

my_string_1

1st_string

hjt

_a

A

1st_string (cant start with a number)

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

Which one of the following has the same precedence level?
Group of answer choices

Multiplication, Division, Addition and Subtraction

Addition and Multiplication

Addition and Subtraction

Multiplication, Division and Addition

A

Addition and Subtraction

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

Which of the following is true for variable names in Python?
Group of answer choices

underscore and ampersand are the only two special characters allowed

all private members must have leading and trailing underscores

none of the mentioned

unlimited length

A

unlimited length

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

The value of the expressions 4/(3(2-1)) and 4/3(2-1) is the same. (T/F)

A

TRUE (BOTH ARE 4/3)

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

What will be the value of the following Python expression? 4 + 3 % 5

A

7

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

What will be the value of x in the following Python expression? x = int(43.55+2/2)

A

44

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

What will be the value of the following Python expression? float(4+int(2.39)%2)

A

4.0

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

What is the answer to this expression, 22 % 3 is?

A

1

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

What is the value of the following expression? 2+4.00, 2**4.0?

A

6.0 16.0

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

The expression 223 is evaluates as: (22)3. (T/F)

A

FALSE (DIFFERENT ANSWERS, 256 AND 64 RESPECTIVELY)

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

Is a high-level, interpreted, interactive and object-oriented scripting language.

A

PYTHON

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

Evaluate the expression given below if A = 16 and B = 15. A % B // A

A

0

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

What symbol was introduce in Python 3.5 known as infix operator?

A

@

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

What will be the value of X in the following Python expression? X = 2+9((312)-8)/10

A

27.2

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

Which of the following expressions results in an error?
Group of answer choices

float(‘10’)

int(’10.8’)

int(‘10’)

A

int(’10.8’)

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

What will be the value of the following Python expression?4+2**5//10

A

7

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

What is the output of this expression, 3*1**3?

A

3

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

What will be the output of the following Python expression? print(4.00/(2.0+2.0))

A

1.0

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

Which of the following is not a keyword?
a) eval b) assert c) nonlocal d) pass

A

eval

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

Which of the following expressions is an example of type conversion?
Group of answer choices

3+7

4.0 + float(3)

5.0 + 3

5.3+6.3

A

4.0 + float(3)

47
Q

Python can run on a wide variety of hardware platforms and has the same interface on all platforms. (T/F)

A

TRUE

48
Q

The elsif is the same as else if in C++. (T/F)

A

FALSE, PYTHON = ELIF, C++ = ELSE IF

49
Q

What will be the output of the following Python expression? 24//6%3, 24//4//2

A

(1, 3)

50
Q

Python allows programmer to define their own type using def function, which are not use for object-oriented programming. (T/F)

A

FALSE

51
Q

What does the following code print to the console?

if 1:

print("1 is truthy!")

else:

print("???")
A

1 is truthy!

52
Q

What does the following code print to the console?

name = “maria”

if name == “melissa”:

print("usa")

elif name == “mary”:

print("ireland")

else:

print("colombia")
A

colombia

53
Q

What will this code print?

a = True

if a:

print("A")

else:

print("B")

print(“C”)

A

A
C

(canvas answer: A C)

54
Q

What (which) statement will check if a is less than or equal to b?

A

if a<=b:

55
Q

The code inside ‘If’ statement is executed only once (T/F)

A

TRUE

56
Q

if False:

print("Nissan")

elif True:

print("Ford")

elif True:

print("BMW")

else:

print("Audi")
A

Ford

57
Q

It is possible to execute both the statements under if and else at the same time. (T/F)

A

FALSE

58
Q

What will this code print?

if 3 < 4:

print("A")

else:

print("B")

print(“C”)

A

A
C

(CANVAS ANS: A C)

59
Q

What does the following code print to the console?

hair_color = “blue”

if 3 > 2:

if hair_color == "black":

    print("You rock!")

else:

    print("Boring")
A

Boring

60
Q

What will this code print?

if 4 < 4:

print("A")

elif 3 < 4:

print("B")

else:

print("C")

print(“D”)

A

B
D

(CANVAS ANS: B D)

61
Q

What does this code print?

a = 0

for i in range(10):

for j in range(10):

    a += 1

print(a)

A

100

62
Q

What does this code display?

for i in range(3):

print("*", end="")

for j in range(3):

print("*", end="")
A

**** (6 Asterisks)

62
Q

What does this code print?

for y in range(2, 12, 2):

print(y + 1)
A

3
5
7
9
11

(The odd numbers 3 to 11)

63
Q

What does the following print to the console.

word = “”

counter = 0

letters = [“c”, “a”, “r”]

while counter < len(letters):

word = word + letters[counter]

counter = counter + 1

print(word)

A

car

64
Q

What does this code print?

a = 0

for i in range(10):

a += 1

for j in range(10):

    a += 1

print(a)

A

110

65
Q

What does this code print?

for y in range(1, 11):

print(y)
A

1
2
3
4
5
6
7
8
9
10

The numbers 1 to 10*

66
Q

What does this code display?

for i in range(3):

for j in range(3):

    print("*", end="")

    print()
A

*
*
*
*
*
*
*
*
*

(9 asterisks in a vertical line)

67
Q

What does this code display?

for i in range(3):

for j in range(3):

    print("*", end="")
A

******* (9 asterisks)

68
Q

What does the following print to the console.

sum = 0

counter = 0

numbers = [22, 55, 111, 555]

while numbers[counter] < 100:

sum = sum + numbers[counter]

counter = counter + 1

print(sum)

A

77

69
Q

What is the output

d = {‘foo’: 1, ‘bar’: 2, ‘baz’: 3}

while len(d) > 3:

print(d.popitem())

print(‘Done.’)

(FA2 20 QUESTIONS PERFECT)

A

Done.

70
Q

(FA3-A1)
What happens if the base condition isn’t defined in recursive programs?

A

Program gets into an infinite loop

71
Q

Which of these is not true about recursion?

Group of answer choices

Recursive functions are easy to debug

Recursive calls take up a lot of memory

Programs using recursion take longer time than their non-recursive equivalent

It’s easier to code some real-world problems using recursion than non-recursive equivalent

A

Recursive functions are easy to debug (hard to debug)

72
Q

What will be the output of the following Python code?

def a(n):

if n == 0:

    return 0

elif n == 1:

    return 1

else:

    return a(n-1)+a(n-2)

for i in range(0,4):

print(a(i),end=" ")
A

0 1 1 2

73
Q

. What will be the output of the following Python code?

def f(x):

print("outer")

def f1(a):

    print("inner")

    print(a,x)

f(3)

f1(1)

A

outer error

74
Q

a = 3

def f():

a = a + 1

print(a)

f()

A

An error, a is undefined.

75
Q

Read the following Python code carefully and point out the global variables?

y, z = 1, 2

def f():

global x

x = y+z
A

y and z

76
Q

What is tail recursion?

Group of answer choices

A function where the recursive call is the last thing executed by the (function)

A recursive function where the function doesn’t return anything and just prints the values

) A function where the recursive functions leads to an infinite loop

A recursive function that has two base cases

A

A function where the recursive call is the last thing executed by the (function)

77
Q

Which is the most appropriate definition for recursion?
Group of answer choices

A class method that calls another class method

A function that calls itself

An in-built method that is automatically called

A function execution instance that calls another execution instance of the same function

A

A function that calls itself

78
Q

What does this code print?

def f(a):

print(a)

a = 5

f(a + 1)

END OF FA3-A1 (7/10)

A

6

79
Q

Which of the following statements is false about recursion?
Group of answer choices

Every recursive function must have a base case

A recursive function makes the code easier to understand

Infinite recursion can occur if the base case isn’t properly mentioned

Every recursive function must have a return value

A

A recursive function makes the code easier to understand

80
Q

Which of these is not true about recursion?
Group of answer choices

A complex task can be broken into sub-problems

Recursive calls take up less memory

Making the code look clean

Sequence generation is easier than a nested iteration

A

Recursive calls take up less memory

81
Q

l=[]

def convert(b):

if(b==0):

    return l

dig=b%2

l.append(dig)

convert(b//2)

convert(6)

l.reverse()

for i in l:

print(i,end="")
A

110

82
Q

def a(n):

if n == 0:

    return 0

elif n == 1:

    return 1

else:

    return a(n-2)+a(n-2)

for i in range(0,4):

print(a(i),end=" ")
A

0 1 0 2

83
Q

x=100

def f1():

global x

x=90

def f2():

global x

x=80

print(x)

A

100

84
Q
  • START OF SA2 -

What will be the output of the following Python code?

x = “abcdef”

i = “a”

while i in x[1:]:

print(i, end = " ")
A

no output

85
Q

What will be the output of the following Python code?

x = “abcdef”

i = “a”

while i in x:

print('i', end = " ")
A

i i i i i i …

86
Q

What will be the output of the following Python code?

d = {0: ‘a’, 1: ‘b’, 2: ‘c’}

for x in d.values():

print(d[x])

Group of answer choices

0 a 1 b 2 c

a b c

None of the mentioned

0 1 2

A

None of the mentioned

87
Q

What will be the output of the following Python code?

i = 5

while True:

if i%0O11 == 0:

    break

print(i)

i += 1
A

5 6 7 8

88
Q

What will be the output of the following Python code?

x = ‘abcd’

for i in range(x):

print(i)

Group of answer choices

error

none of the mentioned

a b c d

0 1 2 3

A

error

89
Q

What will be the output of the following Python code?

x = “abcdef”

i = “a”

while i in x:

x = x[1:]

print(i, end = " ")
A

a

90
Q

i = 1

while True:

if i%2 == 0:

    break

print(i)

i += 2
A

1 2 3 4 5 6 …

91
Q

What will be the output of the following Python code?

for i in range(2.0):

print(i)
A

error

92
Q

What will be the output of the following Python code?

d = {0: ‘a’, 1: ‘b’, 2: ‘c’}

for x in d.keys():

print(d[x])
A

a b c

93
Q

What will be the output of the following Python code?

d = {0, 1, 2}

for x in d:

print(x)
A

0 1 2

94
Q

What will be the output of the following Python code snippet?

x = ‘abcd’

for i in range(len(x)):

x = 'a'

print(x)
A

a a a a

95
Q

What will be the output of the following Python code?

for i in range(int(2.0)):

print(i)
A

0 1

96
Q

What will be the output of the following Python code?

for i in range(float(‘inf’)):

print (i)

Group of answer choices

none of the mentioned

0.0 1.0 2.0 3.0 …

0.0 0.1 0.2 0.3 …

0 1 2 3 …

A

none of the mentioned

97
Q

What will be the output of the following Python code?

d = {0: ‘a’, 1: ‘b’, 2: ‘c’}

for x, y in d:

print(x, y)

Group of answer choices

0 a 1 b 2 c

0 1 2

None of the mentioned

a b c

A

0 1 2

98
Q

What will be the output of the following Python code?

i = 0

while i < 3:

print(i)

i += 1

else:

print(0)
A

0 1 2 0

99
Q

What will be the output of the following Python code?

def sample():

return total + 1

total = 0

print(sample())

A

1

100
Q

If a function doesn’t have a return statement, which of the following does the function return?
Group of answer choices

int

null

An exception is thrown without the return statement

none

A

none

101
Q

What is called when a function is defined inside a class?

A

method

102
Q

What will be the output of the following Python code?

y = 6

z = lambda x: x * y

print z(8)

A

ERROR (?)

  • supposedly SYNTAX ERROR
103
Q

What will be the output of the following Python code?

def sample(k):

k[0] = 1

q = [0]

sample(q)

print(q)

A

[1]

104
Q

What will be the output of the following Python code?

x = 50

def func():

global x

print('x is', x)

x = 2

print('Changed global x to', x)

func()

print(‘Value of x is’, x)

A

x is 50
Changed global x to 2 Value of x is 2

105
Q

What will be the output of the following Python code?

def f(x, y, z): return x + y + z

f(2, 30, 400)

A

NO OUTPUT

106
Q

What will be the output of the following Python code?

def C2F(c):

return c * 9/5 + 32

print C2F(100)

print C2F(0)

Group of answer choices

314 24

212 32

None of the mentioned

567 98

A

212 32

107
Q

What will be the output of the following Python code?

x=12

def f1(a,b=x):

print(a,b)

x=15

f1(4)

A

4 12

108
Q

What will be the output of the following Python code?

a=10

b=20

def change():

global b

a=45

b=56

change()

print(a)

print(b)

A

10
56

109
Q

What will be the output of the following Python code?

def sum(*args):

’'’Function returns the sum

of all values’’’

r = 0

for i in args:

  r += i

return r

print sum.__doc__

print sum(1, 2, 3)

print sum(1, 2, 3, 4, 5)

A

6 15

110
Q

What will be the output of the following Python code?

def f1():

global x

x+=1

print(x)

x=12

print(“x”)

A

x

111
Q

What will be the output of the following Python code?

def sayHello():

print('Hello World!')

sayHello()

sayHello()

A

Hello World! Hello World!

112
Q

What will be the output of the following Python code?

def printMax(a, b):

if a > b:

    print(a, 'is maximum')

elif a == b:

    print(a, 'is equal to', b)

else:

    print(b, 'is maximum')

printMax(3, 4)

A

4 is maximum

113
Q

What will be the output of the following Python code?

i=0

def change(i):

i=i+1

return i

change(1)

print(i)

  • END OF SA2 = 24/30 -
A

0