What is the output of the following code?
1 for i in range(1, 11):
2 print (i, end = " ")
A) 1 2 3 4 5 6 7 8 9
B) 1 2 3 4 5 6 7 8 9 10
C) 1 2 3 4 5
D) 1 3 5 7 9 correct answers B) 1 2 3 4 5 6 7 8 9 10
What is the output of the following code?
1 num = 5
2 for i in range(num, 15):
3 num += i
4 print(num)
A) 10
B) 100
C) 99
D) 15 correct answers B) 100
What is the output of the following code?
1y=4
2 for i in range(y, 15):
3y=i
4 print (y)
A) 4
B) 14
C) 15
D) 13
E) Error, there is no output. correct answers B) 14
Consider the following code:
1 for i in range (1, 6):
2 print(i)
3 else:
4 print("The end.")
What does the code output?
A) 1
2
3
4
5
,The end.
B) 1
2
3
4
5
6
The end.
C) 1
2
3
4
5
D) The end. correct answers A) 1
2
3
4
5
The end.
Consider the following code:
1 for i in range(1, 6.0):
2 print(i)
Which of the following statements is true?
A) It runs fine and displays
1
2
3
4
5
B) There is an error because we cannot use 6.0 in the range.
C) It runs fine and displays
1
2
3
4
5
6 correct answers B) There is an error because we cannot use 6.0 in the range.
Consider the following code:
1i=0
2 while i < 3:
3 print("hi")
4i=i+1
, What's the output?
A) hi
hi
hi
B) hi
hi
C) hi
D) nothing correct answers A) hi
hi
hi
What's the output of the following code?
1 cnt = 0
2 while (cnt < 6):
3 cnt = cnt + 1
4 print(cnt, end="") correct answers 6
What's the output of the following code?
1 cnt = 0
2 while (cnt < 8):
3 cnt = cnt + 3
4 print(cnt, end="") correct answers 9
What is the output of the following code?
1 num = 0
2 sum = 0
3 while (num < 4):
4 sum = sum + num
5 num = num + 1
6 print(sum)
A) 0
B) 6
C) 2
D) 4 correct answers B) 6
What's the output from the following code segment when the input is
1
4
2
5
-2
3
1 cnt = 0
2t=0