ITC Lab Quiz
ITC Lab Quiz
1. Which of the following is the correct way to comment out multiple lines of code in Python?
a) # This is a comment
b) /* This is a comment */
my_list = [1, 2, 3, 4, 5]
print(my_list[2:4])
a) [1, 2]
b) [2, 3]
c) [3, 4]
d) [4, 5]
content = file.read()
words = content.split()
w = set(words)
print(len(w))
numbers = [1, 2, 3, 4, 5]
print(new_numbers)
b) [4, 16]
c) [2, 4]
d) [1, 3, 5]
return a + b
result = add_numbers(5, 7, 2)
print(result)
for i in range(5)
print(i)
8. Identify the correct way to open a file in binary mode for writing:
9. How can you bind a function my_function to a button click event in Tkinter?
a) button.bind(my_function)
b) button.onClick(my_function)
c) button.configure(command=my_function)
d) bind(button, my_function)
10. How can you create a button with the label "Click Me" in Tkinter?
a) Button("Click Me")
b) Button(text="Click Me")
c) Button(label="Click Me")
d) create_button("Click Me")
11. How can you plot a line graph in Matplotlib with x-values [1, 2, 3] and y-values [4, 5, 6]?
12. How can you find the index of the maximum value in a NumPy array arr?
a) index(max(arr))
b) max(arr).index()
c) argmax(arr)
d) find_max_index(arr)
a) for i in range(10):
b) while True:
c) for i in range(5):
d) while False:
a) if value in list:
b) if list.contains(value):
c) if value.contains(list):
d) if list in value:
result = text.count('is')
print(result)
a) 1
b) 2
c) 3
d) 4
17. Identify and correct the error in the following code:
def greet(name):
result = greet("John")
print(result)
a = [1, 2, 3]
a = tuple(a)
a[0] = 2
print(a)
a) [2, 2, 3]
b) (2,2,3)
c) Error
d) (1,2,3)
print(example[-3:-1])
c) ["Tuesday", "Wednesday"]
d) [“Wednesday", "Monday"]
a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
c = [x for x in a if x not in b]
print(c)
a) [1,2]
b) [5,6]
c) [1,2,5,6]
d) [3,4]