Sunteți pe pagina 1din 5

Q1. How many times will the following code print "Welcome A.

8 Level:1
to Python"? B. 9
C. 10
count = 0 D. 11
while count < 10: E. 0
print("Welcome to Python")
count += 1 Answer:
C
Q2. What is the output of the following code? A. x is 0 Level:1
x=0 B. x is 1
while x < 4: C. x is 2
x=x+1 D. x is 3
E. x is 4
print("x is", x) Answer:
E
Q3. Analyze the following code. A. count < Level:2
100 is always
count = 0 True at Point
while count < 100: A
# Point A B. count <
print("Welcome to Python!") 100 is always
count += 1 True at Point
# Point B B
C. count <
# Point C 100 is always
False at Point
B
D. count <
100 is always
True at Point
C
E. count <
100 is always
False at Point
C

Answer;
A,E
Q4. How many times will the following code print "Welcome A. 8 Level:1
to Python"? B. 9
count = 0 C. 10
while count < 10: D. 11
print("Welcome to Python") E. infinite
number of
times

Answer E
Q5. What will be displayed when the following code is A. 6 3 0 Level:2
executed? B. 6 3
C. 3 0
number = 6 D. 3 0 -3
while number > 0: E. 0 -3
number -= 3
print(number, end = ' ') Answer
C
Q6. Analyze the following statement: A. The Level:2
program has
sum = 0 a syntax
for d in range(0, 10, 0.1): error
sum += sum + d because the
range
function
cannot have
three
arguments.
B. The
program has
a syntax
error
because the
arguments in
the range
must be
integers.
C. The
program
runs in an
infinite loop.
D. The
program
runs fine.

Answer:
B
Q7. Which of the following loops correctly computes 1/2 + A. BCD Level:3
2/3 + 3/4 + ... + 99/100? B. ABCD
C. B
A: D. CDE
sum = 0 E. CD
for i in range(1, 99):
sum += i / (i + 1) Answer:

print("Sum is", sum) C


B:
sum = 0
for i in range(1, 100):
sum += i / (i + 1)

print("Sum is", sum)

C:
sum = 0
for i in range(1.0, 99.0):
sum += i / (i + 1)

print("Sum is", sum)

D:
sum = 0
for i in range(1.0, 100.0):
sum += i / (i + 1)

print("Sum is", sum)


Q8. What is the output for y? A. 10 Level:3
B. 11
y=0 C. 12
for i in range(0, 10): D. 13
y += i E. 45
print(y) Answer: E
Q9. Given the following four patterns, A. Pattern A Level:3
Pattern A Pattern B Pattern C Pattern D B. Pattern B
1 123456 1 123456 C. Pattern C
12 12345 21 12345 D. Pattern D
123 1234 321 1234
1234 123 4321 123 Answer:
12345 12 54321 12 C
123456 1 654321 1

Which of the pattern is produced by the following code?

for i in range(1, 6 + 1):


for j in range(6, 0, -1):
print(j if j <= i else " ", end = " ")
print()
Q10 Analyze the following fragment: A. The Level:3
program
sum = d = 0 does not run
while d != 10.0: because sum
d += 0.1 and d are not
sum += sum + d initialized
correctly.
B. The
program
never stops
because d is
always 0.1
inside the
loop.
C. The
program may
not stop
because of
the
phenomenon
referred to
as numerical
inaccuracy
for operating
with floating-
point
numbers.
D. After the
loop, sum is
0 + 0.1 + 0.2
+ 0.3 + ... +
1.9
Answer:
C

Q11 To add 0.01 + 0.02 + ... + 1.00, what order should you A. add 0.01, Level:2
use to add the numbers to get better accuracy? 0.02, ..., 1.00
in this order
to a sum
variable
whose initial
value is 0.
B. add 1.00,
0.99, 0.98,
..., 0.02, 0.01
in this order
to a sum
variable
whose initial
value is 0
Answer:
A
Q12 How many times is the print statement executed? A. 100 Level:2
for i in range(10): B. 20
for j in range(10): C. 10
print(i * j) D. 45
Answer:100
Q13 Will the following program terminate? A. Yes Level:2
B. No
balance = 10
Answer:
while True: A
if balance < 9: break
balance = balance - 9
Q14. What is sum after the following loop terminates? A. 15 Level:3
B. 16
sum = 0 C. 17
item = 0 D. 18
while item < 5:
item += 1 Answer;
sum += item A
if sum >= 4: continue

print(sum)
Q15. What will be displayed by after the following loop A. i is 5 Level:3
terminates? isPrime is
True
number = 25 B. i is 5
isPrime = True isPrime is
for i in range(2, number): False
if number % i == 0: C. i is 6
isPrime = False isPrime is
break True
D. i is 6
print("i is", i, "isPrime is", isPrime) isPrime is
False
Answer: B
Q16. Suppose the input for number is 9. What will be A. i is 3 Level:3
displayed by the following program? followed by
9 is prime
number = eval(input("Enter an integer: ")) B. i is 3
followed by
isPrime = True 9 is not
for i in range(2, number): prime
if number % i == 0: C. i is 2
isPrime = False followed by
9 is prime
print("i is", i) D. i is 2
followed by
if isPrime: 9 is not
print(number, "is prime") prime
break Answer; C
else:
print(number, "is not prime")

S-ar putea să vă placă și