University College Dublin
MIS3011S Introduction to Programming
Practical 8
Miguel Nicolau
- What is the output of the following Python code?
full
stock = 976
current
stock = full
current
stock-= 34
print(full
stock)
stock - What is the output of the following Python code?
featured
brand = “Sony”
brands = [featured
brand, “Canon”, “Nikon”, “Fujifilm”]
featured
brand = “Fujifilm”
print(brands) - What is the output of the following Python code?
root
vine
vegetables = [“turnip”, “carrot”, “potato”]
fruits = [“kiwi”, “grape”, “tomato”]
produce = root
vegetables + vine
del root
vegetables[1]
print(produce)
fruits - What is the output of the following Python code?
travel
plans = [“Mexico”, “USA”, “Panama”, “Cuba”]
current
trip = travel
while len(current
plans
trip) > 0:
print(“Visiting”, current
trip.pop())
print(“Countries left to visit:”, travel
1
plans) - What is the output of the following Python code?
digits = [*range(10)]
lucky
number = digits[5]
digits = digits[1:-1]
print(lucky
number) - What is the output of the following Python code?
operations = [“//”, “**”, “+”, “-”, “*”, “/”]
basic
operations = operations[2:]
operations.pop()
operations.pop()
print(basic
operations) - What is the output of the following Python code?
codes = [351, 32, 353, 33]
new
codes = codes
codes.append(1)
print(new
codes) - What is the output of the following Python code?
codes = [351, 32, 353, 33]
new
codes = list(codes)
codes.append(1)
print(new
codes) - What is the output of the following Python code?
codes = [351, 32, 353, 33]
new
codes = codes
codes = codes[:2]
print(new
codes) - What is the output of the following Python code?
codes = [351, 32, 353, 33]
new
codes = codes
del codes[2]
print(new
codes[2])
2 - What is the output of the following Python code?
codes = [351, 32, 353, 33]
new
codes = codes
del codes[2]
try:
print(new
codes[3])
except:
print(“Code does not exist.”) - What is the output of the following Python code?
codes = [351, 32, 353, 33]
new
codes = codes[:]
del codes[2]
try:
print(new
codes[3])
except:
print(“Code does not exist.”)