# Create comparative statements as appropriate on the lines below!
# Make me true!
bool_one = 1 <= 2
# Make me false!
bool_two = 1 > 2
# Make me true!
bool_three = 1 != 2
# Make me false!
bool_four = 2 > 2
# Make me true!
bool_five = 4 < 5
第四节 1 介绍了第一种连接符and的使用,只有and的两边都是True那么结果才能为True
2 练习
1 设置变量bool_one的值为False and False
2设置变量bool_two的值为-(-(-(-2))) == -2 and 4 >= 16**0.5
3 设置变量bool_three的值为19%4 != 300/10/10 and False
4设置变量bool_four的值为-(1**2) < 2**0 and 10%10 <= 20-10*2
5设置变量bool_five的值为True and True
bool_one = False and False
bool_two = -(-(-(-2))) == -2 and 4 >= 16**0.5
bool_three = 19%4 != 300/10/10 and False
bool_four = -(1**2) < 2**0 and 10%10 <= 20-10*2
bool_five = True and True
第五节 1 介绍了第二种连接符or的使用,只要or的两边有一个True那么结果才能为True
2 练习
1 设置变量bool_one的值为2**3 == 108%100 or 'Cleese' == 'King Arthur'
2设置变量bool_two的值为True or False
3 设置变量bool_three的值为100**0.5 >= 50 or False
4设置变量bool_four的值为True or True
5设置变量bool_five的值为1**100 == 100**1 or 3*2*1 != 3+2+1
bool_one = 2**3 == 108%100 or 'Cleese' == 'King Arthur'
bool_two = True or False
bool_three = 100**0.5 >= 50 or False
bool_four = True or True
bool_five = 1**100 == 100**1 or 3*2*1 != 3+2+1
bool_one = not True
bool_two = not 3**4 < 4**3
bool_three = not 10%3 <= 10%2
bool_four = not 3**2+4**2 != 5**2
bool_five = not not False
第七节 1 介绍了由于表达式很多所以我们经常使用()来把一些表达式括起来,这样比较具有可读性
2 练习
1 设置变量bool_one的值为False or (not True) and True
2设置变量bool_two的值为False and (not True) or True
3 设置变量bool_three的值为True and not (False or False)
4设置变量bool_four的值为not (not True) or False and (not True)
5设置变量bool_five的值为False or not (True and True)
bool_one = False or (not True) and True
bool_two = False and (not True) or True
bool_three = True and not (False or False)
bool_four = not (not True) or False and (not True)
bool_five = False or not (True and True)
第八节
1 练习:请至少使用and,or,not来完成以下的练习
# Use boolean expressions as appropriate on the lines below!
# Make me false!
bool_one = not ((1 and 2) or 3)
# Make me true!
bool_two = not (not((1 and 2) or 3))
# Make me false!
bool_three = not ((1 and 2) or 3)
# Make me true!
bool_four = not (not((1 and 2) or 3))
# Make me true!
bool_five = not (not((1 and 2) or 3)
第九节 1 介绍了条件语句if
2 if的格式如下, 比如
if 8 < 9:
print "Eight is less than nine!"
3 另外还有这elif 以及else,格式如下
if 8 < 9:
print "I get printed!"
elif 8 > 9:
print "I don't get printed."
else:
print "I also don't get printed!"
4 练习:设置变量response的值为'Y'
response = 'Y'
answer = "Left"
if answer == "Left":
print "This is the Verbal Abuse Room, you heap of parrot droppings!"
# Will the above print statement print to the console?
# Set response to 'Y' if you think so, and 'N' if you think not.
第十节
1 介绍了if的格式
if EXPRESSION:
# block line one
# block line two
# et cetera
answer = "'Tis but a scratch!"
def black_knight():
if answer == "'Tis but a scratch!":
return True
else:
return False # Make sure this returns False
def french_soldier():
if answer == "Go away, or I shall taunt you a second time!":
return True
else:
return False # Make sure this returns False