Conditionals
Contents
Conditionals¶
1. if-elif-else
¶
Fill missing pieces (____
) of the following code such that prints make sense.
name = 'John Doe'
if ____:
print('Name "{}" is more than 20 chars long'.format(name))
length_description = 'long'
elif ____:
print('Name "{}" is more than 15 chars long'.format(name))
length_description = 'semi long'
elif ____:
print('Name "{}" is more than 10 chars long'.format(name))
length_description = 'semi long'
elif ____:
print('Name "{}" is 8, 9 or 10 chars long'.format(name))
length_description = 'semi short'
else:
print('Name "{}" is a short name'.format(name))
length_description = 'short'
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/ipykernel_2476/2188967020.py in <module>
----> 1 if ____:
2 print('Name "{}" is more than 20 chars long'.format(name))
3 length_description = 'long'
4 elif ____:
5 print('Name "{}" is more than 15 chars long'.format(name))
NameError: name '____' is not defined
assert length_description == 'semi short'