Reference no: EM132356343
Answer the Following Questions
1. In computation if operands of different types are involved, Python converts the operand with "smaller" type to the "larger" type. What is this called?
1 auto conversion
2 coercion
3 explicit conversion
4 (1) and (2)
2. Which function is used to receive input from users?
1 str()
2 type()
3 print()
4 input()
3. x=4
y=3
product = 4 * 3
What is the correct print statement to output the value of x, y and product?
1 print("The product of %d and %d is %d" %x,%y,%product)
2 print("The product of %d and %d is %d" %(x,y,product))
3 print("The product of %d and %d is %d" %x,y,product)
4 print("The product of %d and %d is %d", %(x,y,product))
4. Which is a valid python statement?
1 a,b=divmod(5,2)
2 x = 6.5>>2
3 m=int(input(‘Enter a number:\n'))
4 All the above are valid
5 Only 1 and 3 are valid
5. What is the for loop that will print the following output?
1 for i in range(1,5): for j in range(1,i+1): print(j, end=' ') print('')
1
1 2 2 for i in range(1,5):
for j in range(1,i+1): print(i)
print('')
1 2 3
1 2 3 4
3 for i in range(1,5):
for j in range(1,i): print(j, end=' ')
print('')
4 for i in range(1,5):
for j in range(1,i+1): print(j, end=' ')
print('')
6. What is the for loop that will print the following output? 1 for i in range(1,5): for j in range(1,i+1): print(i,end=' ')
print('')
1
2 2 2 for i in range(1,5):
for j in range(1,i+1): print(j,end=' ')
print('')
3 3 3
4 4 4 4
for i in range(1,5):
for j in range(1,i): print(i,end=' ')
print('')
3
4 None of these
7. x=not((1 or 0) and (1 and 1)). What is the value of x?
1 True
2 False
8. What is the output of the following code?
i=1;
while i < 10:
i = i+3
print(i,end=' ') 1 4 7
2 4 7 10
3 1 4 7 10
4 1 4 7
9. Which statement about Python is true?
1 In Python there is no need to define variable data type.
2 Python is a compiled language.
3 Python does not support object-oriented programming.
4 A Python variable name can start with a digit.
10.If a=5, b=10 and c=8, the boolean value stored in x after executing the statement
x=a<=b<=c
1 True
2 False
11. The statement a<=b<=c is equivalent to:
1 a<=b and a<=c
2 b<=c and b<=a
3 a<=b and b<=c
4 c<=b and c<=a
12. The if statement that validates variable x for a value between 100 and 1000(both included) is:
1 if(100<=x<=1000):
2 if(x>=100 and x<=1000):
3 if(x>100 and x<1000):
4 Only 2 and 3
5 Only 1 and 2
13. What would the following statement return?
list=[‘Mary', ‘John', 12, ‘Dog']
print (list[-3:-1])
1 ['Mary', 'Dog']
2 ['John', 'Dog']
3 ['John', 12]
4 ['Mary', '12']
14.What is the output of the following code snippet?
i=1
while i <=10: if i%2 == 0:
i=i+1 continue
print(i,end=' ')
i+=1
1 1 3 5 7 9
2 2 4 6 8 10
3 1 4 7 10
4 None of these
15. What is the output of the following code?
for i in(1,2,3,4,5):
if i//3 == 0: continue
print(i//3,end=' ')
1 0 0 0
2 3 4 5
3 1 2 3
4 None of these
16. What is the output of the following code?
for i in (3,6,9,12,15): if i==9:
break
print(i,end=' ')
1 3 6 12 15
2 3 6 9
3 3 6
4 None of these
17. Which of the code snippets will create an infinite loop? 1 a=1 while 1:
print(a) a+=1
if a==5:
break
2 a=1 while 1:
print(a) if a>10:
break
3 a=1
while a>=1:
a=a+1 print(a)
4 Only 1 and 3
5 Only 2 and 3
18. Which of the range functions will return a list that is not empty?
1 range(1,1)
2 range(10,1,2)
3 range(1,10,-2)
4 range(10,1,-2)
5 Options 2 and 4.
19. What is the type of value returned by the input() function?
1 Dependent on the value read from the console.
2 String
3 Integer
4 None of these.
20. Which is not a keyword in Python?
1 pass
2 break
3 continue
4 statement
5 and