Professional Documents
Culture Documents
MT Exercise
MT Exercise
MT Exercise
# 1) What is the content of the 'L' after the execution of the following
code segment?
L = [1, 2, 3, 4, 5, 6]
del L[1:4]
L.append(8)
L.insert(1, 7)
# a) [1, 7, 8]
# b) [1, 2, 7, 8]
# c) [1, 6, 8, 7]
# d) [1, 7, 5, 6, 8]
# e) [2, 7, 3, 4, 5, 6, 7, 8]
##############################################################
# 2) What is the output of the following code segment?
a = 25
b = 15
h(8, 4)
print(a, b)
##############################################################
# a) ['Ceng', 'Metu']
# b) ['ceng', 'metu']
# c) ['ceng', 'Metu']
# d) ['CENG', 'METU']
# e) []
##############################################################
# 4) What will be the content of 'my_list' after executing the following
code?
# a) ['Ceng', 'Metu']
# b) ['ceng', 'metu']
# c) ['ceng', 'Metu']
# d) ['CENG', 'METU']
# e) []
##############################################################
i = 1
while True:
if i % 5 == 0:
break
print(i, end=' ')
i += 2
# a) 0 2 4
# b) 0 2 4 6 8
# c) 1 3
# d) 1 3 5
# e) 1 3 5 7 9
##############################################################
##############################################################
# a) [8, 'Ceng']
# b) [8, -2, 'Ceng']
# c) [0, 8, {}, -2, '', 'Ceng', []]
# d) [False, True, False, True, False, True, False]
# e) [False, True, False, False, False, True, False]
##############################################################
print('Milky Way')
##############################################################
my_dictionary = {}
for i in range(2):
for j in range(3):
my_dictionary[i] = j
print(my_dictionary)
# a) {0: 2, 1: 2}
# b) {0: 0, 0: 1, 0: 2, 1: 0, 1: 1, 1: 2}
# c) {0: 2, 1: 2, 2: 2, 3: 2}
# d) [0: 2, 1: 2, 2]
# e) Error, no output
##############################################################
# 10) What is the output of the following program?
my_list = [1, 'a', [], 4]
my_list.append([5, 6, 7])
print(len(my_list))
# a) 5
# b) 7
# c) 6
# d) 8
# e) Error, no output
##############################################################
my_tuple = (1, 2, 3)
another_tuple = 2 * my_tuple
print(another_tuple)
# a) (2, 4, 6)
# b) ((1, 1), (2, 2), (3, 3))
# c) (1, 2, 3, 1, 2, 3)
# d) (1, 2, 3)
# e) Type Error, multiplication is not defined for tuples
##############################################################
##############################################################
# a) 1
# b) 2
# c) 3
# d) 7
# e) 10
##############################################################
i = 0
while i < 3:
print(i, end=' ')
i += 1
print(i+1, end=' ')
###############################################################
###############################################################
###############################################################
# a) Error b) 0 1 2 2 c) 0 1 2 3 d) 0 1 2 0
###############################################################
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
# a) Error b) 0 1 2 0 c) 0 1 2 3 d) 0 1 2
###############################################################
# a) 1 1 b) 1 44 c) 3 1 d) 3 44
###############################################################
x = 3
y = 5
i = x-1 if x > y else x*y
print(i)
# a) x*y b) False c) 2 d) 15