# Wrong:
b = True
if (not b):
print('no')
else:
print('yes')
|
# Right:
b = True
if (b):
print('yes')
else:
print('no')
|
# Wrong:
b = False
if (b):
pass
else:
print('no')
|
# Right:
b = False
if (not b):
print('no')
|
# Wrong (though not so wrong...):
b1 = True
b2 = True
if (b1):
if (b2):
print('both!')
|
# Right (well, maybe just "preferred"):
b1 = True
b2 = True
if (b1 and b2):
print('both!')
|
# Wrong:
b = True
if (b):
print('yes')
if (not b):
print('no')
|
# Right:
b = True
if (b):
print('yes')
else:
print('no')
|
# Wrong:
x = 10
if (x < 5):
print('small')
if ((x >= 5) and (x < 10)):
print('medium')
if ((x >= 10) and (x < 15)):
print('large')
if (x >= 15):
print('extra large')
|
# Right:
x = 10
if (x < 5):
print('small')
elif (x < 10):
print('medium')
elif (x < 15):
print('large')
else:
print('extra large')
|
# Wrong:
c = 'a'
if ((c >= 'A') and (c <= 'Z')):
print('Uppercase!')
if ((c >= 'a') and (c <= 'z')):
print('lowercase!')
if ((c < 'A') or
((c > 'Z') and (c < 'a')) or
(c > 'z')):
print ('not a letter!')
|
# Right:
c = 'a'
if ((c >= 'A') and (c <= 'Z')):
print('Uppercase!')
elif ((c >= 'a') and (c <= 'z')):
print('lowercase!')
else:
print('not a letter!')
|
# Wrong:
x = 42
y = ((x > 0) and 99)
|
# Right:
x = 42
if (x > 0):
y = 99
|