if else control structures in python Flashcards

1
Q

What is the output of the code snippet below?

value = 4

a = str(value)
b = a + “^” + “2”
c = a + “^” + “3”

print(value, “+”, b, “+”, c)

A

4 + 4^2 + 4^3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the output of the program below?

var = “hi”
if(type(var) == int):
print(“Type of the variable is Integer”)
elif(type(var) == float):
print(“Type of the variable is Float”)
elif(type(var) == complex):
print(“Type of the variable is Complex”)
else:
print(“Type of the variable is Unknown”)

A

Type of the variable is Unknown

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

if ‘bin’ in {‘float’: 1.2, ‘bin’: 0b010}:
print(‘a’)
print(‘b’)
print(‘c’)

A

a b c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Evaluate the expression provided. What does the following expression evaluate to?

‘1’ + ‘2’ if ‘123’.isdigit() else ‘2’ + ‘3’

A

‘12’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Question

How is the body of an if-statement block syntactically represented in Python?

A

Using additional indentation from the left relative to lines just before and after the block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

new_list = [“Red”, “Blue”, “White”, “Green”]
z = sorted(new_list)
d = list(z)
d[0], d[1], d[2], d[3] = d[3], d[2], d[1], d[0]

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What do the values of d[0], d[1], d[2], d[3] evaluate to after the execution of the Python code below?

new_list = [“Red”, “Blue”, “White”, “Green”]
z = sorted(new_list)
d = list(z)
d[0], d[1], d[2], d[3] = d[3], d[2], d[1], d[0]

A

“White”, “Red”, “Green”, “Blue”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Consider the following snippet of Python code:

a = “40.6 ”
b = “60.4 ”
c = a + b

What does c evaluate to?

A

‘40.6 60.4 ‘

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the value of b in the snippet of python code?

a = “six”
b = (int(a), float(a))

A

ValueError: invalid literal for int() with base 10: ‘six’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly