wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz AX-7

Total questions: 81

Worksheet time: 59mins

Name
Class
Date
1.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

2.

What is the output of the code above

a)

None

b)

Syntax Error

c)

-1

d)

Code doesn't compile

3.

The output of the code above is

a)

Key Error

b)

4

c)

Math

4.

The code above prints

a)

Math

Physics

Chemistry

English

b)

4

3.8

3.6

3.7

c)

None

None

None

None

d)

NaN

NaN

NaN

NaN

5.

What is the output of the program above

a)

e

b)

y

c)

t

d)

g

6.

The output of the code above is

a)

[101, 102, 103, 104]

b)

[3.6, 3.7, 3.8, 4]

7.

What is the output of the code above

a)

[3.6, 3.7, 3.8, 4]

b)

[101, 102, 103, 104]

8.

Assume the key is the student's id and the value is the grade. Which of the following code will get the grade of student id 102.

a)

grades[102]

b)

grades.get(102)

c)

grades[2]

d)

grades[3]

e)

grades.key(102)

9.

Which of the following are valid ways to create a dictionary like this

a)
b)
c)
d)
e)
10.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
11.

What is the output of the code above

a)

3.9

b)

4

c)

Syntax error

12.

What is the output of the program above

a)

7

b)

6

c)

5

d)

9

e)

4

13.

How to fix the syntax error above ?

a)

grades.pop("Science", None)

b)

grades.pop["Science","None"]

c)

del grades["Math"]

d)

del grades["Math", None]

14.

What is the problem with the code above ?

a)

Dictionary cannot be changed during an iteration

b)

This code will run fine (without syntax errors)

c)

After all the grades are popped, there are no elements remaining. The print statement will throw a syntax error.

15.

Tuples in Python are mutable

a)

False

b)

True

16.

How to create a single element tuple

a)

(1,)

b)

(1)

c)

{1}

d)

[1]

e)

tuple([1])

17.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

18.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

19.

What is the output of the code above

a)

(1, '2', 3, 4, 5)

b)

syntax error

c)

(1, 2, 3, 4, 5)

d)

('1', '2', '3', '4', '5')

20.

Which of the following is true

a)

a is assigned a value of 1

b)

b is assigned a value of [2,3]

c)

b is assigned a value of (2,3)

d)

b is assigned a value of 2

21.

What is the output of the program above ?

a)

b is bigger

b)

a is bigger

c)

Syntax error : tuples can't be compared

22.

What is the output of the code above ?

a)

1 4

b)

1

c)

1 None

d)

1 [2,3,4]

e)

1 (2,3,4)

23.

What is the output of the program above ?

a)

True

b)

False

24.

Find T ?

T=144 / 2 + 5 * 9 - ( 8 -3 )

a)

106

b)

688

c)

112

d)

684

25.

Find the Output:

Item = {"ECE" , "CSE" , "EEE" , "CIVIL"}

Item.add (2,"MECH")

print(Item)

a)

{ "ECE" , "MECH" , "CSE" , "EEE" , "CIVIL" }

b)

{ "ECE" , "CSE" , "MECH" , "EEE" , "CIVIL" }

c)

{ "ECE" , "CSE" , "EEE" , "CIVIL" }

d)

{ "ECE" , "CSE" , "EEE" ,"MECH" , "CIVIL" }

26.

Find the Output ?

A = "Anand Institute of higher technology"

print ( A[-5:7]

a)

_Institute of higher techn

b)

nstitute of higher technol

c)

d Institute of higher techn

d)

Institute of higher techno

27.

def.number (r1 , r2)

sum = r1 / r2

return sum

a = number (r2 = 15 , r1 = 10)

a)

2 / 3

b)

3 / 2

c)

error

d)

2

28.

what is the output of the following code ?

var1 = 1

var2 = 2

var3 = "3"


print (var + var2 var3)

a)

Error. Mixing operators between numbers and strings are not supported

b)

6

c)

33

d)

123

29.

Which of the following function convert a string to a float in python ?

a)

float(X)

b)

int(x[,base])

c)

long(X[,base])

d)

str(X)

30.

what is the output of the following programing ?

X = [ 'ab' , 'cd' ]

for i in X:

i.upper()

print (x)

a)

[ 'AB' , 'CD' ]

b)

[ 'ab' , 'cd' ]

c)

[ AB , CD ]

d)

ERROR

31.

find p ?

p = ( 35 , 46 , 73 , 21 )

p.append( -2 , 24 )

print (p)

a)

( 35 , 46 , 73 , 24 , 21 )

b)

error

c)

( 35 , 46 , 24 , 73 , 21 )

d)

( 35 , 24 , 73 , 21 )

32.

what will be the output of the following python code snippet ?

not (10 < 20) and not (10 > 30 )

a)

TRUE

b)

FALSE

33.

Find the output ?

a = True

b = False

c = False

if a or b and c :

print "INFYTQ"

else:

print "infytq"

a)

infytq

b)

INFYTQ

c)

ERROR

34.

In a Python program, a control structure:

a)

Defines program-specific data structures

b)

Directs the order of execution of the statements in the program

c)

Manages the input and output of control characters

d)

Dictates what happens before the program starts and after it terminates

35.

Syntax error in python is detected by _________at _______

a)

interpreter/ run time

b)

compiler/ compile time

c)

compiler/ run time

d)

interpreter/ compile time

36.

Which one of the following if statements will not execute successfully:

a)

if (1, 2):


print('foo')

b)

if (1, 2):

print('foo')

c)

if (1, 2):

print('foo')

d)

if (1, 2): print('foo')

e)

if (1, 2):

print('foo')

37.

Which among them will produce {'a', 'b', 'c'}?

a)

Tuple(''abc'')

b)

Set(''abac'')

c)

List(''abc'')

d)

None of the above.

38.

Which among them is incorrect for set s={100,101,102,103}

a)

Max(s)

b)

Sum(s)

c)

Len(s)

d)

Print(s[3])

39.

What signifies the end of a statement block or suite in Python?

a)

A comment

b)

end

c)

A line that is indented less than the previous line

d)

}

40.

What is the output for −

S = [['him', 'sell'], [90, 28, 43]]

S[0][1][1]

a)

'e'

b)

'i'

c)

'90'

d)

'h'

41.

The following if/elif/else statement will raise a KeyError exception:


d = {'a': 0, 'b': 1, 'c': 0}

2

3if d['a'] > 0:

4 print('ok')

5elif d['b'] > 0:

6 print('ok')

7elif d['c'] > 0:

8 print('ok')

9elif d['d'] > 0:

10 print('ok')

11else:

12 print('not ok')

a)

TRUE

b)

FALSE

42.

What is the output of the following

l = [None] * 10

print(len(l))

a)

10

b)

0

c)

Syntax Error

43.

Select all the correct options to copy a list


aList = ['a', 'b', 'c', 'd']

a)

newList = copy(aList)

b)

newList = aList.copy()

c)

newList.copy(aList)

d)

newList = list(aList)

44.

The output of the code above will be

a)

0

b)

1

c)

99

45.

How to add these two numbers

a)

age = int(age_1) + int(age_2)

b)

age = int(age_1 + age_2)

c)

age = age_1 + age_2

46.

The string enclosed in triple quotes is called the doc string. It is used to

a)

Show the documentation about the function

b)

be read by the developer reading the function code

47.

Which of the following code is true

a)

square() will return 25

b)

square(3) will return 9

48.

Which of the following is true

a)

The code above will result in syntax error

b)

square(2,2) will result in a value of 4

c)

square(2,3) will result in a value of 9

49.

The above code is the signature of the print function in Python.


*objects represents

a)

Variable number of arguments that can be passed as strings

b)

pointer to objects in memory

50.

The code above

a)

Takes in variable number of arguments and returns the sum of them

b)

Takes in a pointer to a list of numbers and returns the sum of them

51.

The output of the code above is

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'dict'>

d)

<class 'string'>

e)

<class 'iterable'>

52.

The output of the code above is

a)

40

b)

30

c)

syntax error

53.

What is the output of Following code?

List = ['spam', 2.0, 5, [10, 20]]

print(List[2])

(a)  

54.

What is the output of Following code?

cheeses = ['Cheddar', 'Edam', 'Gouda']

numbers = [42, 123]

print(cheeses, numbers)

a)

['Cheddar', 'Edam', 'Gouda'] [42, 123]

b)

[42, 123] ['Cheddar', 'Edam', 'Gouda']

c)

Compilation Error

d)

No output

55.

What is output of the following Code (Execute in Intrepreter)

cheeses = ['Cheddar', 'Edam', 'Gouda']

'Edam' in cheeses

(a)  

56.

In Python, list is mutable

a)

True

b)

False

57.

Which of the following commands will create a list?

a)

list1 = list()

b)

list1 = []

c)

list1 = list([1, 2, 3])

d)

list1 = new List()

58.

What is the output of the following code?

list = [1,2,3,4,5,6,7,8,9,10]

print(list[1:2])

(a)  

59.

What is the output of the following code?

list = [1,2,3,4,5,6,7,8,9,10]

print(list[2:1])

(a)  

60.

What is the output of the following code?

list = [1,2,3,4,5,6,7,8,9,10]

print(list[::-1])

a)

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

b)

[1,2,3,4,5,6,7,8,9,10]

c)

Error

d)

No output

61.

What is the output of the following code?

list = [1,2,3,4,5,6,7,8,9,10]

print(list[::-3])

a)

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

b)

Compilation error

c)

[8,9,10]

d)

[10, 7, 4, 1]

62.

What is the output of the following code?

list = []

list.append(1)

list.append(2.0)

list.append("vk")

print(list)

a)

[1, 2.0, 'vk']

b)

Error

c)

['vk', 1, 2.0]

d)

No putput

63.

What will be the output of the following Python code?

a)

a) 1

2

3

b)

b) error

c)

c) 1

2

d)

d) none of the mentioned

64.

What are the values of the following Python expressions?

2**(3**2)

(2**3)**2

2**3**2

a)

a) 512, 64, 512

b)

b) 512, 512, 512

c)

c) 64, 512, 64

d)

d) 64, 64, 64

65.

What will be the output of the following Python program?

a)

a) error

b)

b) 0 1 2 0

c)

c) 0 1 2

d)

d) none of the mentioned

66.

What will be the output of the following Python code?

a)

a) 1 2 3 4 5 6

b)

b) 1 2 3 4 5 6 7

c)

c) error

d)

d) none of the mentioned

67.

What will be the output of the following Python code?

a)

a) 1

b)

b) 1 3 5 7.....

c)

c) 1 2 3 4..... .

d)

d) none of the mentioned

68.

What will be the output of the following Python code?

a)

a) a b c d

b)

b) 0 1 2 3

c)

c) error

d)

d) none of the mentioned

69.

What will be the output of the following Python code?

a)

a) a b c d

b)

b) 0 1 2 3

c)

c) error

d)

d) 1 2 3 4

70.

What will be the output of the following Python code?

a)

a) 0 1 2

b)

b) a b c

c)

c) {0: 'a', 1: 'b', 2: 'c'}

{0: 'a', 1: 'b', 2: 'c'}

{0: 'a', 1: 'b', 2: 'c'}

d)

d) none of the mentioned

71.

What will be the output of the following Python code?

for i in range(0):

print(i)

a)

a) 0

b)

b) no output

c)

c) error

d)

d) none of the mentioned

72.

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

a)

a) 0 1 2 3 4 …

b)

b) 0 -2

c)

c) 0

d)

d) error

73.

What will be the output of the following Python code?

a)

a) 0 1 2 3 4 Here

b)

b) 0 1 2 3 4 5 Here

c)

c) 0 1 2 3 4

d)

d) 1 2 3 4 5

74.

1. True of False: When increased readability or elimination of complexity are important, then normal predefined python functions may be of more value than corresponding Lambda ones.

a)

a. True

b)

b. False

75.

2. Which of the following statements about

Python Lambda functions are true? Select all that apply:

a)

a. Lambda functions are used with functional programming.

b)

b. Lambda functions can be useful as quick, throwaway, single line functions.

c)

c. Lambda Functions are useful as input to other functions

d)

d. All of the above.

76.
a)

a. 10

b)

b. 10.0

c)

c. num

d)

d. SyntaxError, return is invalid

77.

4. What are the common functional programming functions

that use lambdas? Select all that apply:

a)

a. filter()

b)

b. map()

c)

c. reduce()

d)

d. lookup()

78.
a)

a. Syntax error, lambda functions cannot contain the named key parameter

b)

b. No output, exception will be raised on middle line

c)
d)
e)
79.

6. What did you like most about this training session? All feedback welcome.

4 lines
80.

7. To receive a copy of the guide, please enter your personal internet email below.

4 lines
81.

Which of the following is the output of the below Python code?


var1 = lambda var: var * 2

ret = lambda var: var * 3

result = 2

result = var1(result)

result = ret(result)

result = var1(result)

print(result)

a)

24

b)

12

c)

7

d)

36

e)

48