Which of the following is the walrus operator?
a. ;=
b. =
c. =:
d. :=
d. :=
After the execution of the following statement, the variable sold will reference the numeric literal value as ________ data type.
sold = 256.752
a. str
b. currency
c. float
d. int
c. float
Which of the following is the correct if clause to determine whether y is in the range 10 through 50, inclusive?
a. if y >= 10 and y <= 50:
b. if 10 < y or y > 50:
c. if y >= 10 or y <= 50:
d. if 10 > y and y < 50:
a. if y >= 10 and y <= 50:
In a "while" loop, what happens if the loop condition is initially false?
a. The loop will not execute
b. The loop will execute indefinitely
c. The loop will execute once
d. An error will occur
a. The loop will not execute
What is the purpose of the "break" statement in a "for" loop?
a. Skips the rest of the loop and continues with the next iteration
b. Exits the entire loop prematurely
c. Skips the current iteration and moves to the next one
d. Breaks the loop into two separate loops
b) Exits the entire loop prematurely
Which method can be used to place an item at a specific index in a list?
a. insert ()
b. add ()
c. append ()
d. index ()
a. insert ()
What is the result of the following expression in Python?
int(round (8.24671, 3))
a. 8.24671
b. 8
c. 8.246
6. 8.24
b. 8
After this code executes, what value will be stored in the variable z?
x = 0
y = 9
z = 1 if x > y else 50
a. 50
b. 0
c. 1
d. 9
a. 50
How can you create an infinite loop using a "while" statement?
a. while True:
b. while 1 == 1:
c. while False:
d. while condition:
a. while True:
What is the output of the following code?
for i in range(3):
print(i)
a. 0 1 2
b. 1 2 3
c. 1 1 1
d. 0 0 0
a. 0 1 2
What is the output of the following statement?
print('One'
'Two'
'Three')
a. One
Two
Three
b. One Two Three
c. OneTwoThree
d.Nothing–This statement contains an error.
c. OneTwoThree
What is the output of the following code?
val = 123.456789
print(f'{val:.3f}')
a. 123.457
b. 123.456789
c. 123.456
d.123
a. 123.457
Which of the following is the correct if clause to determine whether choice is anything other than 10?
a. if choice != 10\
b. if not(choice < 10 and choice > 10):
c. if choice != 10:
d. if choice <> 10:
c. if choice != 10:
How many times will the following loop iterate?
count = 0
while count < 3:
count += 2
break
else:
count += 1
print(count)
a. 1
b. 2
c. 3
d. 4
b. 2
What will be the output pf the following script?
fruits = ['apple', 'orange', 'banana']
for fruit in fruits:
print(fruit.capitalize())
a. Apple, Orange, Banana
b. APPLE, ORANGE, BANANA
c. apple, orange, banana
d. a, o, b
a. Apple, Orange, Banana
What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8?
x < y or z > x
a. 8
b. 5
c. False
d. True
d. True
What is the result of the following script?
a, b, c = 8.14, 10.5, 2.48
print (int (a) + round (b + c))
print (int (a) + int (b) + c)
a. 21 , 20.48
b. 20.48, 21.12
c. 21.12, 20
d. 20.48, 21.14
a. 21 , 20.48
Which of the following shows the correct way to use the walrus operator?
a. score := input('What is your score? ')
if score > 90:
print('That is a great score!')
b. if score := input('What is your score?' ) > 90: print('That is a great score!')
c. if (score = input('What is your score? ')) > 90: print('That is a great score!')
d. if (score := input ('What is your score? ')) > 90: print('That is a great score!')
d. if (score := input ('What is your score? ')) > 90: print('That is a great score!')
What is the purpose of the "pass" statement in the following code?
num = 0
while num < 3:
num += 1
pass
a. To terminate the loop immediately
b. To skip the rest of the loop and move to the next iteration
c. To execute a specific block of code in the loop
d. It has no effect on the loop
d. It has no effect on the loop
In a list comprehension, what does this expression produce?
[x for x in range(10) if x % 2 == 0]
a. A list of even numbers from 0 to 9
b. A list of all numbers from 0 to 9
c. An empty list
d. A list of odd numbers from 0 to 9
a. A list of even numbers from 0 to 9
What is the output of the following statement?
print('I\'m ready to begin')
a. Im ready to begin
b. I'm ready to begin
c. I\'m ready to begin
d. 'I\'m ready to begin'
b. I'm ready to begin
The backslash (\) is used as an escape character in the string to indicate that the following character (') should be treated as a literal character, allowing you to include a single quote within a single-quoted string.
Which list will be referenced by the variable number after the following code is executed?
number = range(0, 9, 2)
a. [2, 4, 6, 8]
b. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
c. [1, 3, 5, 7, 9]
d. [0, 2, 4, 6, 8]
d. [0, 2, 4, 6, 8]
What values will list2 contain after the following code executes?
list1 = [1, 10, 3, 6]
list2 = [item * 2 for item in list1 if item > 5]
a. [[1, 10, 3, 6],[1, 10, 3, 6]]
b. [20, 12]
c. [10, 6]
d.[2, 20, 6, 12]
b. [20, 12]
What is the output of the following code?
i = 1
while i < 5:
i *= 2
else:
i -= 1
print(i)
a. 4
b. 5
c. 7
d. 8
c. 7
***************
Here is the output for i:
2
4
8
7
What will be the value of the result list?
numbers = [1, 2, 3, 4, 5]
result = [x * x for x in numbers if x % 2 == 0]
a. [1, 4, 9, 16, 25]
b. [4, 16]
c. [2, 4]
d. [16, 4, 16]
b. [4, 16]