Professional Documents
Culture Documents
CSBP119 SP2023 LCN 03
CSBP119 SP2023 LCN 03
CHAPTER 3
Decision Structures
and Boolean Logic
• Python syntax:
if condition:
Statement1
Statement2
• First line known as the if clause
• Includes the keyword if followed by condition
• The condition can be true or false
• When the if statement executes, the condition is tested,
and if it is true the block statements are executed. otherwise,
block statements are skipped
>>> x = 1 Enter
>>> y = 0 Enter
>>> y < x Enter
True
>>> x < y Enter
False
>>>
HIGH_SCORE = 95
test = int(input('Enter the score for test: ' ))
if test >= HIGH_SCORE:
print('Congratulations!’)
print('That is a great score!')
name1 = 'Mary'
name2 = 'Mark'
if name1 > name2:
print('Mary is greater than Mark')
else:
print('Mary is not greater than Mark')
Program Output:
Mary is greater than Mark
TURTLE GRAPHICS
if turtle.isdown():
turtle.penup()
if not(turtle.isdown()):
turtle.pendown()
if turtle.isvisible():
turtle.hideturtle()