# Conditionals
# The IF statement
# But we need some operators
#
# Relational operators:
# Operators
# "A symbol that performs a task"
# e.g. +, -, *, /, **
# Relational operators compare:
# >, <, >=, <=
# == "comparative equal"
# ("is equal to")
# != "bang equals" - "not equal to"
# Relational operators take numeric
# operands and return a "Boolean"
# (logical) value of True or False
# Boolean operators
# take Boolean operands and return
# a Boolean value
# Logical AND: and
# Logical OR: or
# Logical NOT: not
# e.g. a<5 and b>23
# Logical AND:
# True iff both operands are True
# Suppose:
x = 2
y = -4
x > 0 and y < 0 --> True
x > 0 and y < -4 --> False
# Logical OR:
# True if either operand (or both)
# is True
x>0 or y<-4 --> True
x>5 or y<-4 --> False
# Logical NOT:
# Inverts the logical value
not (x>5) --> True
not (x>0 or y<-4) --> False
# This works
a = True
# Now, conditionals
#
# IF statement
# General format:
# Simple version
# if :
# ```
if b>3:
print('Hey! b is greater than 3!')
if a<3 or c>27:
print('Don''t do that!')
if (a<3 or c>27):
print('Don''t do that!')
print
print
print
# If the condition is True, all the code
# within the body is executed; other-
# wise the code is skipped
# Example:
# Suppose we want to do the quadratic
# formula. Solution for
# 0 = ax^2 + bx + c
# (-b +/- sqrt(b^2 - 4ac))/(2a)
# The solution is the roots (the
# values of x which make the eqn
# true
# Example: 3x^2 - 27x + 10 = 0
# What are the roots?
# With a computer, we simply need
# to code in the values of a, b,
# and c and compute using the
# quadratic formula:
r1 = (-b + sqrt(b**2 - 4*a*c)/(2*a)
# We want our program to compute the
# the roots only when the equation
# is a true quadratic - when a != 0
if a != 0:
# Compute roots
r1 = (-b + sqrt(b**2 - 4*a*c)/(2*a)
r2 = (-b - sqrt(b**2 - 4*a*c)/(2*a)
# Let's extend this with the ELSE
# clause (optional)
else:
print('Error: a must not be 0!')
```