Algo Pekan 05
Algo Pekan 05
Algo Pekan 05
Muhamad Sabar
Informatics Engineering
Sekolah Tinggi Teknologi Bandung
2019
Prev
Python
1. Intro to Python
2. Comments
3. Data Type
4. Variable
5. Operator
Decision & Loops
Decision
The if–else is used to make choices in Python code. This is a compound
statement. The simplest form is
if c o n d i t i o n :
a c t i o n −1
else:
a c t i o n −2
The indentation is required. Note that the else and its action are
optional. The actions action-1 and action-2 may consist of many
statements; they must all be indented the same amount. The condition
is an expression which evaluates to True or False. Of course, if the
condition evaluates to True then action-1 is executed, otherwise action-
2 is exe-cuted. In either case execution continues with the statement
after the if-else.
x=1
if x > 0:
print " Friday is wonderful"
else:
print " Monday sucks"
print " Have a good weekend"