Get Latest Exam Updates, Free Study materials and Tips

Document

Quiz 1

Q.1:

Is Python case sensitive when dealing with identifiers?

A) Yes B) No
C) Machine dependent D) None of the mentioned
Q.2:

What is the maximum possible length of an identifier?

A) 31 characters B) 63 characters
C) 79 characters D) None of the mentioned
Q.3:

Which of the following is invalid?

A) _a = 1 B) __a = 1
C) __str__ = 1 D) None of the mentioned
Q.4:

Which of the following is an invalid variable?

A) my_string_1 B) 1st_string
C) foo D) _
Q.5:

Why are local variable names beginning with an underscore discouraged?

A) they are used to indicate a private variables of a class B) they confuse the interpreter
C) they are used to indicate global variables D) they slow down execution
Q.6:

Which of the following is not a keyword?

A) eval B) assert
C) nonlocal D) pass
Q.7:

All keywords in Python are in _________

A) lower case B) UPPER CASE
C) Capitalized D) None of the mentioned
Q.8:

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

A) unlimited length B) all private members must have leading and trailing underscores
C) underscore and ampersand are the only two special characters allowed D) none of the mentioned
Q.9:

Which of the following is an invalid statement?

A) abc = 1,000,000 B) a b c = 1000 2000 3000
C) a,b,c = 1000, 2000, 3000 D) a_b_c = 1,000,000
Q.10:

Which of the following cannot be a variable?

A) __init__ B) in
C) it D) on
Q.11:

Which is the correct operator for power(xy)?

A) X^y B) X**y
C) X^^y D) None of the mentioned
Q.12:

Which one of these is floor division?

A) / B) //
C) % D) None of the mentioned
Q.13:

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 B) ii,i,iii,iv,v,vi
C) ii,i,iv,iii,v,vi D) i,ii,iii,iv,vi,v
Q.14:

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

A) 7 B) 1
C) 0 D) 5
Q.15:

Mathematical operations can be performed on a string.

A) True B) False
Q.16:

Operators with the same precedence are evaluated in which manner ?

A) Left to Right B) Right to Left
C) Can’t say D) None of the mentioned
Q.17:

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

A) 27 B) 9
C) 3 D) 1
Q.18:

Which one of the following has the same precedence level?

A) Addition and Subtraction B) Multiplication, Division and Addition
C) Multiplication, Division, Addition and Subtraction D) Addition and Multiplication
Q.19:

The expression Int(x) implies that the variable x is converted to integer.

A) True B) False
Q.20:

Which one of the following has the highest precedence in the expression?

A) Exponential B) Addition
C) Multiplication D) Parentheses
Q.21:

What is the output of print 0.1 + 0.2 == 0.3?

A) True B) False
C) Machine dependent D) Error
Q.22:

Which of the following is not a complex number?

A) k = 2 + 3j B) k = complex(2, 3)
C) k = 2 + 3l D) k = 2 + 3J
Q.23:

What is the type of inf ?

A) Boolean B) Integer
C) Float D) Complex
Q.24:

What does ~4 evaluate to ?

A) -5 B) -4
C) -3 D) +3
Q.25:

What does ~~~~~~5 evaluate to?

A) +5 B) -11
C) +11 D) -5
Q.26:

Which of the following is incorrect?

A) x = 0b101 B) x = 0x4f5
C) x = 19023 D) x = 03964
Q.27:

What is the result of cmp(3, 1)?

A) 1 B) 0
C) True D) False
Q.28:

Which of the following is incorrect?

A) float(‘inf’) B) float(‘nan’)
C) float(’56’+’78’) D) float(’12+34′)
Q.29:

What is the result of round(0.5) – round(-0.5) ?

A) 1.0 B) 2.0
C) 0.0 D) Value depends on Python version
Q.30:

What does 3 ^ 4 evaluate to ?

A) 81 B) 12
C) 0.75 D) 7
Q.31:

Which of the following statements assigns the value 25 to the variable x in Python:

A) x ← 25 B) x = 25
C) int x = 25 D) x << 25
Q.32:

In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type:

A) False B) True
Q.33:

Which one of the following is the correct way of declaring and initializing a variable, x with the value 7 ?

A) x=7 B) int x
C) int x=7 D) declare x=7
Q.34:

What will be the output of statement 2**2**2**2

A) 16 B) 256
C) 32768 D) 65536
Q.35:

Which of the following statement is False ?

A) Variable names can be arbitrarily long. B) They can contain both letters and numbers.
C) Variable name can begin with underscore. D) Variable name can begin with number.
Q.36:

What is the output of the following code: print 9//2

A) 4 B) 4.5
C) 4.0 D) Error
Q.37:

Which of the following is not a valid variable name in Python?

A) _var B) var_name
C) var11 D) 5var
Q.38:

What is the maximum length of an identifier in python?

A) 32 B) 31
C) 63 D) None of the above
Q.39:

Which of the following declarations is incorrect?

A) None Of the below B) _x = 2
C) __x = 3 D) __xyz__ = 5
Q.40:

What is the result of round(0.5) – round(-0.5)?

A) 1.0 B) 2.0
C) 0 D) None Of the above
Q.41:

What is the result of executing the following code?

number = 5

while number <= 5:

if number < 5:

number = number + 1

print(number)

A) The program will loop indefinitely B) The value of number will be printed exactly 1 time
C) The while loop will never get executed D) The value of number will be printed exactly 5 times
Q.42:

What will the following code print ?

counter = 1

sum = 0

while counter <= 6:

sum = sum + counter

counter = counter + 2

print(sum)

A) 12 B) 9
C) 7 D) 8
Q.43:

What will be printed by the following code when it executes?

sum = 0

values = [1,3,5,7]

for number in values:

sum = sum + number

print(sum)

A) 4 B) 0
C) 7 D) 16
Q.44:

What is the last thing printed when the following code is run ?

number = 0

while number <= 10:

print("Number: ", number)

number = number + 1

A) Number: 10 B) Number: number
C Number: 0 D) Number: 11
Q.45:

What does the following code print ?

output = ""

x = -5

while x < 0:

x = x + 1

output = output + str(x) + " "

print(output)

A) 5 4 3 2 1 B) -4 -3 -2 -1 0
C) -5 -4 -3 -2 -1 D) This is an infinite loop, so nothing will be printed
Q.46:

What are the values of var1 and var2 that are printed when the following code executes ?

output = ""

var1 = -2

var2 = 0

while var1 != 0:

var1 = var1 + 1

var2 = var2 - 1

print("var1: " + str(var1) + " var2 " + str(var2))

A) var1 = -2, var2 = 0 B) var1 = 0, var2 = -2
C) var1 = 0, var2 = -1 D) This is an infinite loop, so nothing will be printed
Q.47:

How many asterisks will be printed when the following code executes? for x in [0, 1, 2, 3]: for y in [0, 1, 2, 3, 4]: print('*')

A) 0 B) 4
C) 5 D) 20
Q.48:

The following code contains an infinite loop. Which is the best explanation for why the loop does not terminate ?

n = 10 answer = 1 while n > 0: answer = answer + n n = n + 1 print(answer)

A) n starts at 10 and is incremented by 1 each time through the loop, so it will always be positive. B) answer starts at 1 and is incremented by n each time, so it will always be positive.
C) You cannot compare n to 0 in the while loop. You must compare it to another variable. D) In the while loop body, we must set n to False, and this code does not do that.
Q.49:

Which type of loop can be used to perform the following iteration: You choose a positive integer at random and then print the numbers from 1 up to and including the selected integer.

A) a for-loop or a while-loop B) only a for-loop
C) only a while-loop D) a for-loop And a while-loop
Q.50:

Which of the following statements won’t be printed when this Python code is run?

for letter in 'Python': if letter == 'h': continue print('Current Letter : ' + letter)

A) Current Letter : P B) Current Letter : t
C) Current Letter : h D) Current Letter : o
Q.51:

for i in range(-3), how many times this loop will run ?

A) 0 B) 1
C) Infinite D) Error
Q.52:

for i in [1,2,3]:, how many times a loop run ?

A) 0 B) 1
C) 2 D) 3
Q.53:

for loop in python are work on

A) range B) iteration
C) Both of the above D) None of the above
Q.54:

How many times it will print the statement ?, for i in range(100): print(i)

A) 101 B) 99
C) 100 D) 0
Q.55:

For loop in python is

A) Entry control loop B) Exit control loop
C) Simple loop D) None of the above
Q.56:

In which of the following loop in python, we can check the condition ?

A) for loop B) while loop
C) do while loop D) None of the above
Q.57:

It is possible to create a loop using goto statement in python ?

A) Yes B) No
C) Sometimes D) None of the above
Q.58:

To break the infinite loop , which keyword we use ?

A) continue B) break
C) exit D) None of the above
Q.59:

l=[],for i in l: print(l), what is the output ?

A) [] B) list
C) print() D) None of the above
Q.60:

What is the final value of the i after this, for i in range(3): pass

A) 1 B) 2
C) 3 D) 0
Q.61:

What is the value of i after the for loop ?, for i in range(4):break

A) 0 B) 1
C) 3 D) 2
Q.62:

What we put at the last of the loop ?

A) semicolon B) colon
C) comma D) None of the above
Q.63:

which of the following is consider as a infinite loop

A) while(infinte): B) while(1):
C) for(1): D) None of the above
Q.64:

Which of the following is Exit control loop in python ?

A) for loop B) while loop
C) do while loop D) None of the above
Q.65:

Which of the following is the loop in python ?

A)for B) while
C) do while D) 1 and 2
Q.66:

Which of the following loop is not supported by the python programming language ?

A) for loop B) while loop
C) do while loop D) None of the above
Q.67:

Which of the following loop is work on the particular range in python ?

A) for loop B) while loop
C) do while loop D) recursion
Q.68:

While(0), how many times a loop run ?

A) 0 B) 1
C) 3 D) infinite
Q.69:

while(1): print(2), How many times a loops run ?

A) 1 B) 2
C) 3 D) None of the above
Q.70:

while(1==3):, how many times a loop run ?

A) 1 B) infinite
C) 3 D) 0