NEW
Font size
WorksheetsDCSMAT-DataStructures-Condititonal-iterative
Total questions: 20
Worksheet time: 10mins
Which of these commands adds a new item, "banana," to the end of the list fruits?
fruits.append("banana")
fruits.add("banana")
fruits.insert("banana")
fruits.push("banana")
Which conditional expression checks if total_sales is over $500?
total_sales == 500
total_sales < 500
total_sales > 500
total_sales != 500
Which of these commands removes the first item from the list 'vegetables'?
vegetables.remove(0)
vegetables.pop(0)
vegetables.delete(0)
vegetables.shift()
Which conditional expression checks if 'username' is not empty?
username == ""
username != ""
username > ""
username < ""
Which loop type is most suitable for iterating through each item in a list of customer names?
while loop
for loop
if statement
switch statement
How do you access the value of "price" in the dictionary product = {"name": "apple", "price": 1.5}?
product["price"]
product(price)
product->price
product.price
Which conditional expression correctly checks if a number x is even?
if x % 2 == 0:
if x % 2 != 0:
if x / 2 == 1:
if x * 2 == 0:
If sales = [200, 400, 500, 300], what function finds the highest sales figure?
max(sales)
min(sales)
sum(sales)
average(sales)
Given a list items = ["apple", "banana", "apple", "orange"], which command counts how many times "apple" appears?
Which loop sums only the positive numbers in the list numbers = [-3, 5, -1, 6, 8]?
for num in numbers: if num > 0: total += num
for num in numbers: if num < 0: total += num
for num in numbers: total += num
for total in numbers: if num > 0
What command would you use to sort the list numbers = [3, 1, 4, 1, 5] in ascending order?
numbers.sort()
numbers.order()
sorted(numbers)
numbers.arrange()
Which command would you use to check if the key 'email' exists in the dictionary user_info = {"name": "John", "age": 30}?
'email' in user_info
user_info.has_key('email')
user_info.contains('email')
user_info.check('email')
Which of these commands would create a new list containing only the even numbers from the list numbers = [1, 2, 3, 4, 5]?
even_numbers = [num for num in numbers if num % 2 == 0]
even_numbers = filter(lambda x: x % 2 == 0, numbers)
even_numbers = list(filter(lambda x: x % 2 == 0, numbers))
even_numbers = numbers.even()
If sales = 700, which nested statement prints "High Sales" only if sales > 500 and sales < 1000?
if sales > 500 and sales < 1000: print("High Sales")
if sales > 500 or sales < 1000: print("High Sales")
if sales < 500 and sales < 1000: print("High Sales")
if sales > 500 or sales > 1000: print("High Sales")
How do you change the first item in the list products = ["apple", "banana", "mango"] to "orange"?
products[0] = "orange"
products[1] = "orange"
products.add("orange")
products.replace("apple", "orange")
What command would you use to reverse the order of the list colors = ["red", "green", "blue"]?
colors.reverse()
colors.invert()
reversed(colors)
colors.flip()
Which command would you use to remove the key 'age' from the dictionary user_info = {"name": "John", "age": 30}?
del user_info['age']
user_info.remove('age')
user_info.pop('age')
user_info.delete('age')
Which conditional expression checks if a variable 'status' is equal to 'active'?
status == 'active'
status != 'active'
status > 'active'
status < 'active'
Which command would you use to find the length of the list items = ["apple", "banana", "orange"]?
len(items)
items.length()
items.size()
count(items)
What command would you use to convert the string "123" to an integer?
int("123")
str("123")
float("123")
number("123")
