if else control structures in python Flashcards
What is the output of the code snippet below?
value = 4
a = str(value)
b = a + “^” + “2”
c = a + “^” + “3”
print(value, “+”, b, “+”, c)
4 + 4^2 + 4^3
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”)
Type of the variable is Unknown
if ‘bin’ in {‘float’: 1.2, ‘bin’: 0b010}:
print(‘a’)
print(‘b’)
print(‘c’)
a b c
Evaluate the expression provided. What does the following expression evaluate to?
‘1’ + ‘2’ if ‘123’.isdigit() else ‘2’ + ‘3’
‘12’
Question
How is the body of an if-statement block syntactically represented in Python?
Using additional indentation from the left relative to lines just before and after the block
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]
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]
“White”, “Red”, “Green”, “Blue”
Consider the following snippet of Python code:
a = “40.6 ”
b = “60.4 ”
c = a + b
What does c evaluate to?
‘40.6 60.4 ‘
What is the value of b in the snippet of python code?
a = “six”
b = (int(a), float(a))
ValueError: invalid literal for int() with base 10: ‘six’