What would the value of x be if we executed the following code?

a = 1
b = 2
x = a + b
x = 10

1
2
3
4
1

10

Check ALL true statements.

Multi Select
1
2
3
4
2

Lists can contain any type of object.

3

Dictionaries represent pairs of keys and values.

4

List and tuple indexing start from zero.

What does the following code output?

the intensity = 125.11
print(the intensity)

1
2
3
3

SyntaxError: invalid syntax

What would the value of x be if we executed the following code?

x = str(int(float('2')))

1
2
3
1

'2'

What does the code below output?

if not 1 in [10, 20] and 1 < 2:
    print(1)
else:
    print(2)

1
2
3
1

1

What does list(range(2, 5)) output?

1
2
3
3

[2, 3, 4]

Consider this list:

animals = ['bear', 'rat', 'cow', 'shrimp', 'shark']

Which code would extract the slice ['cow', 'shrimp', 'shark'] out of the animals list?

1
2
3
1

animals[2:]

Consider this line of code:

numbers = ('a', 'b', 1, 2)

Check all that would output 2.

Multi Select
1
2
3
4
2

numbers[3]

3

numbers[-1]

What does the code below return?

air_temperature = [35, 28, 10]
land_temperature = [18, 20, 15]
air_temperature[1] + land_temperature[0]

1
2
3
2

46

What's the output of the code below?

mylist = [['abc'], ['def', 'ghi']]
mylist[-1][-1][-1]

1
2
3
4
3

'i'

What does the following code output?

d = {
    "food": {
        "rice":
            {
                "weight": 30.1,
                "taste": "good",
                "forms": ["boiled"]
            },
        "banana":
            {
                "weight": 19,
                "taste": "excellent",
            }
        }
}

print(d['food']['banana']['taste'])

1
2
3
4
4

excellent

Which of the following is a list of tuples of dictionaries?

1
2
2

[({'a':1, 'b':2}, {'c':3, 'd':4}), ({'e':5}, {'d':6})]

Check all the syntactically correct.

Multi Select
1
2
3
4
1

(1, 2)

2

(('a', 1), ('b', 1))

4

{'a': 1, 'b': 2}

What does the code below output?

def eur_to_usd(euros, rate=0.8):
    return euros * rate
print(eur_to_usd(10))

1
2
3
3

8.0

What would the following code output?

x = 10.0

if type(x) == float:
    print(int(x))
else:
    print(x)

1
2
3
4
3

10

What does the code output this time?

x = 10
y = 11

if x > 10 and y > 10:
    print("Success!")
else:
    print("Failed!")

1
2
3
3

Failed!

Check ALL that apply to the following code.

items = ['adapter', 'cable', 'keyboard']

choice = input("Item")
if choice in items:
    print("Item is available!")

Multi Select
1
2
3
1

The execution will be halted to wait for user input.

What would be the output of the following code if the user entered 10 as input?

weight = input("How many kg?")
price = weight * 2.5
print(price)

1
2
3
3

TypeError: can't multiply sequence by non-int of type 'float'

Which code prints out Price is 25.0 when the user enters 10 as input?

1
2
3
3
weight = float(input("How many kg?"))
price = weight * 2.5
print(f"Price is {price}")

What would the following code output?

for letter in 'abc':
    print(letter.upper())

1
2
3
2

A
B
C

What does the following code output?

for item in [[1, 2, 3], [4, 5, 6]]:
    print(item[0])

1
2
3
4
4

1
4

Select the correct output for the following code.

for i in [99, 102, 89]:
    if i >= 100:
        print(i - 1)

1
2
3
4
3

101

What would the value of x be after running the code below?

x = [len(item) for item in ['abc', 'def', 'ghi']]

1
2
3
3

[3, 3, 3]

What would be the value of y given the following code?

y = [i * 2 if i > 0 else 0 for i in [1, -2, 10]]

1
2
3
3

[2, 0, 20]

What would the output of the following code be?

def foo(*args):
    return len(args)
print(foo(1, 2, 4))

1
2
3
4
3

3

def foo(x):
    return x ** 2
print(foo("Hello"))

What is true about the above code?

1
2
3
1

It will produce an error.

What does the code output?

def foo(a = 1, b = 'John'):
    return a + b
foo()

1
2
3
4
3

TypeError: unsupported operand type(s) for +: 'int' and 'str'

What would be the value of price?

def foo(a = 1, b = 2):
    return a + b
price = foo(b = 4)

1
2
3
4
2

5

Which of the code would successfully create a text file? Check all that apply.

Multi Select
1
2
3
4
1
with open('temp.txt', 'w') as file:
    file.write('Hello')
4
file = open('temp.txt', 'w')
file.write("Hello")
file.close()

What would be the content of articles.txt file after executing the following script?

with open('articles.txt', 'w') as file:
        file.write('wiki_telephones')

with open('articles.txt', 'w') as file:
        file.write('wikipedia_telephones')

1
2
3
4
4

wikipedia_telephones