From c7bcd95ac07f9074594edf37893fb92fc41d75d9 Mon Sep 17 00:00:00 2001 From: Joe James Date: Thu, 27 Feb 2020 08:14:50 -0600 Subject: [PATCH] Create if_else.py --- python/if_else.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 python/if_else.py diff --git a/python/if_else.py b/python/if_else.py new file mode 100644 index 0000000..1ecfd06 --- /dev/null +++ b/python/if_else.py @@ -0,0 +1,20 @@ +# if statements are conditional. +# inside the if statement only executes if the condition +# evaluates to True. +# indention is critical. +# all statements inside the if must have same indention. +pressure = 52 + +if pressure > 50: + print("WARNING! High Pressure") + print("I like cashews.") + +# after an if, you can also have elif and/or else statements +if pressure > 50: + print("WARNING! High Pressure") +elif(pressure > 30 and pressure <= 50): # short for else if + print("Normal Pressure") + print("I like macademias.") +# else will execute only when if and elif statements all evaluate to False. +else: + print("Low Pressure.")