CSC- 101 INTRODUCTION
TO COMPUTERS
Question Bank Set - 1
Goutham Aduri
gaduri@jazanu.edu.sa https://cs.tutorialsight.com/
TABLE OF CONTENTS
MULTIPLE CHOICE ON VARIABLES 2
CODING EXERCISE ON VARIABLES 13
MULTIPLE CHOICE ON OPERATORS 14
MULTIPLE CHOICE ON DATA STRUCTURES 24
MULTIPLE CHOICE ON CONTROL FLOW 38
MULTIPLE CHOICE ON TYPECASTING AND ESCAPE SEQUENCES 41
MULTIPLE CHOICE ON VARIABLES
What is wrong with the following code?
number_of items = 10
Nothing is Wrong
Variable Name is Wrong
I don’t know
Underscore is not allowed
What type of variable it is?
x = "2.48"
Integer
Float
String
Double Float
What type of variable it is?
wrong = False
Float
Bool
Integer
String
What is the output of the following program?
a) $x = 100
print($x)
A. 100
B. $100
C. 100.0
D. Syntax Error
What is the output of the following program? a) x1 = 100
b) x2y = 200
print(x1)
print(x2y)
A. 200
100
B. 100
200
C. 100 200
D. Syntax Error
Which one of these is a floating point number?
A. 3.2
B. 4
C. 500
D. “500.45”
Which of these will output the result 36? A: 30+*6
B: 6^6
C: 6**6 D: 6*6
Ans: D
In Python 3, what is the output of 1/2 ?
1
0
C. 0.5
D. None of the Above
Ans: C
What is printed by? print(3**2+1)
7
28
10
16
None of the above.
What is printed by?
val1 = 2
val2 = 3
val1, val2 = val2, val1 print(val1, val2)
3 2
2 3
2
3
None of the above.
11. .What is printed by this sequence of instructions?
x = 0
y = 1
z = 1
print(x or (y and not z))
1
0
True
False
None of the above.
What is printed by? a = 30
if a == 3 or not(a < 20): print("Yes")
else:
print("No")
Yes
No
a is 3
None
None of the above.
What is the correct way to add a comment in Python?
What is the correct way to set a variable 's' equal to the string "Hello World"?
What type of variable is this?
a = True
What type of variable is this? x = 100.45
What is printed by: print(2**2*2)
15
8
16
6
None of the above
Given
value = input("Input a number: ")
What is the type of value if 7 is input at the prompt?
int
str
float
long
None of the above
What is printed by? print(3**2+1)
7
28
10
16
None of the above.
What is printed by?
val1 = 2
val2 = 3
val1, val2 = val2, val1
print(val1, val2)
3 2
2 3
2
3
None of the above.
What is printed by: print(5**2)
10
25
5
True
None of the above
Fill in the Blank to Print “Hi”
>>>> (“Hi”)
Printf
Println
Output
Print
Which of the these will not be stored as a float a) 7.0
b) 7
c) 7/2
d) All the Above
Fill in the Blank with the output of this code
>> 1 + 2 + 3 + 4.0 + 5
>>
a) 15.00
b) 15
c) 15.0
d) None of the Above
Fill in the Blank to make this code correct
>> (1+ ) ** 2 16
a) 3
b) 3.0
c) 2
d) 2.0
What is the Output of this code
>> print(‘print(“print”)’)
An Error Message
‘print(“print”)
print(“print”)
“print(‘print’)”
Fill in the blank to prompt for user input
>>> (“Enter a number”)
Print
Scan
Input
Output
What is printed by?
val1 = 3
val2 = 2
val1, val2 = val2, val1 print(val1, val2)
3 2
2 3
2
3
None of the above.
CODING EXERCISE ON VARIABLES
Define 3 Variables with the Following Data
1. 200
2. 100.111
3. “Hello”
Now print in this format 20
100.111
Hello
The target of this exercise is to create a string, an integer, and a floating point
mystring
number. The string should be named
myint
The floating point number should be named 10.0, and the integer should be named
and should contain the word "hello". and should contain the number
myfloat
and should contain the number 20.
# change this code mystring = None myfloat = None myint = None
# testing code
if mystring == "hello": print("String: %s" % mystring)
if isinstance(myfloat, float) and myfloat == 10.0: print("Float: %f" % myfloat)
if isinstance(myint, int) and myint == 20: print("Integer: %d" % myint)
MULTIPLE CHOICE ON OPERATORS
What is the Output of the Following Program? a. X = (2+ 3)*5
b. print(X)
26
24
25
Syntax Error
What is the Output of the following Program
a) x = 100
y = 2
result = x%y
print(result)
50
0
1
D. 102
What is the output?
result = divmod(50, 6)
print(result)
A. (7, 2)
B. (8, 0)
C. (8, 2)
D. (8, 1)
2 + 5*2
What is the output of the following program? a.
10
12
11
9
2 * 3 / 2
What is the output of the following program? a.
A. 2.99
B. 3
C. 3.0
D. 3.01
What does the modulus operator do (%)?
What is the result of 1. a = 10
2. b = 3
a *= b
Note: The review question comply all the probable questions containing each chapter from the
16
textbook. It gives just the idea about the pattern and layout of the questions and does not
What is the result of this code?
a = "Hello"
b = "World"
print(b*3)
What is the result of the following code?
a = "Hello"
b = "World"
c = a + b
print(c)
Given: x = -1
which expression returns True?
A) 0 <= x <= 15
B) x <= -12
C) x < 110
All of the above
None of the above
What is printed by: print(2 and 3)
2
-1
3
False
None of the above
Given: x = 0 what is printed by:
if x:
print("Here") else:
print("There")
Here
There
None of the above
What is printed by this sequence of instructions?
x = 0
y = 1
z = 1
print(x or (y and not z))
1
0
True
False
None of the above.
Given: x = 12
what is printed by: print(0 <= x <= 12)
False
True
12
0
None of the above.
Given
b = input("Input a bool (True/False): ")
What is the type of b if True is input at the prompt?
float
str
int
bool
None of the above.
What does this output
>>> 1 + 2 + 3
6
7
5
8
Which option is output by this Code?
>>>(4 + 8) / 2
a)8 b)6.0
c)6
d)4
Fill in the Blank (Red Color) to make this code correct?
>>> (_5-1)*3
Output: 18
e) +
–
*
/
Fill in the Blank that will cause a ZeroDivisionError
>>>(17+94)/(-5 + _)
-0
0
5
-5
What is the result of this code?
>> 7%(5//2)
0
7
1
None of the Above
What is printed by
print(3*2**3)
18
16
24
64
None of the above.
What is printed by: print(3 and 2)
2
3
2 and 3
5
None of the above
What is printed by this sequence of instructions?
x = 1
y = 0
z = 1
print(x or (y and not z))
1
0
True
False
None of the above.
MULTIPLE CHOICE ON DATA STRUCTURES
How do you declare a list with the integer elements 1, 2, and 3.
What is the main difference between a tuple and a list?
What are the pairs in dictionaries called?
How would you access the value stored in key 'x' of a dictionary 'd'
4. Given: S1 = {1,2,3} and S2 = {2,3,4}
what is the value of S after this operation: S = S1 & S2
A) {1, 2, 3, 4}
B) {2, 3}
C) {1, 4}
{}
None of the above
What is the correct way to get the number of 'x's in the string 's'
What is the correct way get the substring 'abc' from the string s containing 'abcdefg'
Given: s = 'spam'
what is printed by: print(s.index('s'))
0
''
None
-1
None of the above
Consider this code L1 = ['a','b']
L2 = [1, L1, 2]
L1.append('c') print(L2) # Line 1
What is printed by Line 1?
A) [1, ['a', 'b'], 2]
B) [1, ['a', 'b', 'c'], 2]
C) [1, ['c'], 2]
D) [1, [['a', 'b'],['c']], 2]
E) None of the above
What is printed by this sequence of instructions?
L1 = [2,4]
L2 = [3,5]
print(L1 + L2)
A) [2, 4, 3, 5]
B) [2, 3, 4, 5]
C) [[2, 4], [3, 5]]
D) [2, 4, [3, 5]]
E) None of the above.
Which of the following prints the first three multiples of three: 3 6 9
for i in range(3,12,3): print(i, end=' ')
for i in range(1,5): print(3*i, end = ' ')
for i in range(3): print(3*i, end=' ')
All of the above.
None of the above.
Given s = "Head, Shoulders, Knees and Toes" which code produces the following?
['Head', 'Shoulders', 'Knees and Toes']
s.split(',') # Note no space
s.split(', ') # Note one space after comma
s.split().strip()
list(s)
None of the above.
Consider this code L1 = [1,2]
L2 = [3, L1, 4]
L1.append(5) print(L2) # Line 1
What is printed by Line 1?
A) [3, 'L1', 4]
B) [3, [1, 2], 4]
C) [3, [5], 4]
D) [3, [1, 2, 5], 4]
E) None of the above
Given this sequence of instructions:
L1 = [1,2,3]
L2 = ['a',L1[:],'b',L1]
L1.append(4) print(L2)
What is printed?
A) ['a',L1[:],'b',L1]
B) ['a', [1, 2, 3, 4], 'b', [1, 2, 3, 4]]
C) ['a', [1, 2, 3], 'b', [1, 2, 3, 4]]
D) ['a', [1, 2, 3,4], 'b', [1, 2, 3]]
E) None of the above.
What is printed by
T1 = (7,8)
T1 += (2,1)
print(T1)
A) ((7, 8), (2, 1))
B) (7, 8, 2, 1)
C) (9, 9)
D) (1, 2)
E) None of the above
Given M = {'Bob': 75, 'Alice': 27}
What is printed by print(M['Alice'])
75
27
'Alice'
'Alice': 27
None of the above.
. The key of a dictionary must be:
an int, float, or string
an int or string
Mutable
Immutable
None of the above.
17. Given: S1 = {1,2,3} and S2 = {1,3,5}
what is the value of S after this operation: S = S1 ^ S2
A) {}
B) {1, 3}
C) {2, 5}
D) {1, 2, 3, 5}
E) None of the above
Fill in the missing part of the output
>>>”””First Line Second line”””
‘First Line Second line
\t
\n
\r
None of the above
What line of code produces an error? a) “one” + “2”
b) 3 + 4
c) “7” + ‘eight’
d) ‘5’ + 6
What is the output of this code?
>> print(3*’7’)
a) 21
b) 3*’7’
c) 333
d) 777
What is printed by this sequence of instructions
L1 = [6, 3, 7, 9, 1]
L2 = sorted(L1) print(L1)
A) [9, 7, 6, 3, 1]
B) [6, 3, 7, 9, 1]
C) [1, 3, 6, 7, 9]
None
None of the above.
22. Given D = {'x': 2, 'y': 4}
What is printed by
print(D['x'])
2
4
C) 'x': 2
'x'
None of the above.
What is printed by
T1 = (1,2)
T2 = (7,8)
print(T2+T1)
A) ((7, 8), (1, 2))
B) (7, 8, 1, 2)
C) (10, 8)
D) (7, 8) + (1, 2)
E) None of the above
Given s = "Twinkle, Twinkle, Little Star" which code produces the following?
['Twinkle', 'Twinkle', 'Little Star']
list(s)
s.split().strip()
s.split(', ') # one space character after comma
s.split(',') # no space character
None of the above.
What is printed by this sequence of instructions?
L1 = [3,5]
L2 = [2,4]
print(L1 + L2)
A) [2, 3, 4, 5]
B) [3, 5, 2, 4]
C) [[3, 5], [2, 4]]
D) [3, 5, [2, 4]]
E) None of the above.
MULTIPLE CHOICE ON CONTROL FLOW
What is the result of this conditional statement?
1. x = 3
2. if x == 4:
print("True")
else:
print("False")
True
False
Error
None of the Above
2. B, C, D = 0, 0, 0
for A in [ 0, 1, 3, 5, 7, 9 ]:
if A :
if A%2 == A:
B += 1
else:
C += 1
if A%3 == 0: D += 1
break
print( A ) # Line 1 print( B ) # Line 2 print( C ) # Line 3 print( D ) # Line 4
. What is printed by Line 1 of Figure 2?
0
1
2
3
None of the above
What is printed by Line 2 of Figure 2?
0
1
2
3
None of the above
What is printed by Line 3 of Figure 2?
0
1
2
3
None of the above
What is printed by Line 4 of Figure 2?
0
1
2
3
None of the above
What is printed by? a = 30
if a == 3 or not(a < 20): print("Yes")
else:
print("No")
Yes
No
a is 3
None
None of the above.
What is printed by? a = 20
if a == 3 or not(a < 10): print("No")
else:
print("Yes")
Yes
No
a is 3
None
None of the above
MULTIPLE CHOICE ON TYPECASTING AND ESCAPE SEQUENCES
What is the newline escape sequence?
What is the correct way to convert an integer to a string and store it in the variable 'result'?
What is the output of this code ?
>> int (“3” + “4”)
a) 34
b) “34”
c) “7”
d) 7
What is the output of this code?
>> float(“210” * int(input(“Enter a number: “)))
Enter a number: 2
a) “420.0”
b) “210210”
c) 210210.0
d) 420
What is the output of this code?
>> x = 5
>> y = x + 3
>> y = int(str(y) + “2”)
>>print(y)
10
تعليقات
إرسال تعليق
شاركنا الآراء ،،