# Noemi Cabrera
# 29 November 2021
# In this lesson, I learned how to use the basic Boolean operators (and, or, not), combine comparisons using the basic boolean
# operators, create Boolean expressions that yield equal results, and employ combined comparisons to control program flow
# (i.e. if statements).
# I didn't have any major difficulties in this lesson.

# In this code, the not boolean operator is used to reverse the True and False values. The 'not True' equals False.
# The 'not False' equals True.
# not operator
print("not True = ", not True)
print("not False = ", not False)

# In this code, the 'and' boolean operator is used with the True and False values. The only case where the and operator
# is True is when both values used are True.
# and operator
print("False and False = ", False and False)
print("False and True = ", False and True)
print("True and False = ", True and False)
print("True and True = ", True and True)

# In this code, the 'or' boolean operator is used with the True and False values. The only case where the or operator
# is False is when both values used are False.
# or operator
print("False or False = ", False or False)
print("False or True = ", False or True)
print("True or False = ", True or False)
print("True or True = ", True or True)

# In this code, the 'and', 'or' , and 'not' boolean operators are used together along with True and False values.
# Since not False equals True, the first print statement equals True because both values are True.
# Since not True equals False, the second print statement equals False because both values are False.
print("True and not False =", True and not False)
print("False or not True = ", False or not True)

# In this code, relational and arithmetic operators are used to evaluate 3 expressions to True and 3 to False
# using the x and y variables as the values in the expressions.
# [ ] Use relational and/or arithmetic operators with the variables x and y to write:
# 3 expressions that evaluate to True (i.e. x >= y)
# 3 expressions that evaluate to False (i.e. x <= y)
x = 84
y = 17
# 3 expressions generating True
print(x >= y )
print(x + y == 101)
print(y < x)
print()
# 3 expressions generating False
print(y >= x)
print(84 * 17 == 101)
print(y == x)

# In this code, the basic boolean operators are used to evaluate 3 expressions to True and 3 to False
# using the x and y variables as the values in the expressions.
# [ ] Use the basic Boolean operators with the variables x and y to write:
# 3 expressions that evaluate to True (i.e. not y)
# 3 expressions that evaluate to False (i.e. x and y)
x = True
y = False
# 3 expressions generating True
print(not y)
print(x or y)
print(x and not y)
# 3 expressions generating False
print(not x)
print(x and y)
print(y and not x)

# In this code, the 'or' operator is used to determine of the value of x is outside of the range from 10 to 20.
# If x is true for either condition in the statement, x is outside of range. Since x is 11, it's inside the range
# and False will display.
# Testing if x is outside the range [10, 20]
x = 11
(x < 10) or (x > 20)

# In this code, the 'or' operator is used to determine if the value of x is outside of the range that is
# from 10 to 20. If x is true for either condition in the statement, x is outside of range. Since x is 50,
# it's outside the range and True will display.
# Testing if x is outside the range [10, 20]
x = 50
(x < 10) or (x > 20)

# In this code, the 'and' operator is used to determine if the value of x is positive and odd.
# If x is true for both conditions in the statement, the result is always going to be true. Since
# 11 is a positive and odd number, True is displayed.
# Testing if x is a positive and odd number
x = 11
(x > 0) and (x % 2 != 0)

# In this code, the 'and' operator is used to determine if the value of x is positive and odd.
# If x is true for both conditions in the statement, the result is always going to be true. Since
# -11 is an odd but not positive number, False is displayed.
# Testing if x is a positive and odd number
x = -11
(x > 0) and (x % 2 != 0)

# In this code, the 'and' operator is used to determine if the value of x is positive and odd.
# If x is true for both conditions in the statement, the result is always going to be true. Since
# 22 is a positive but not an odd number, False is displayed.
# Testing if x is a positive and odd number
x = 22
(x > 0) and (x % 2 != 0)

# In this code, the 'and' operator is used to determine if 'name' starts with C and the 'age' is less than
# or equal to 18. If both statements about the variables are true, then the result is always going to be true.
# Since Collete starts with C and the age of 17 is less than 18, True is displayed.
# Driver information
name = 'Colette'
age = 17
# Testing if name starts with `C` and the age is 18 or less
(name.startswith('C')) and (age <= 18)

# In this code, the 'and' operator is used to determine if 'name' starts with C and the 'age' is less than
# or equal to 18. If both statements about the variables are true, then the result is always going to be true.
# Since John doesn't start with C, the entire and statement becomes False because this condition
# evaluates to False.
# Driver information
name = 'John'
age = 17
# Testing if name starts with `C` and the age is 18 or less
(name.startswith('C')) and (age <= 18)

# In this code, the 'and' and 'or' operators are used to determine if 'x' is an even number outside the
# [-100,100]. If both statements used with the and operator about the x are true, then the result is always going to be true.
# However if any of the statements about x evaluate to false, then the output is always going to be False.
# [ ] Write an expression to test if x is an even number outside the range [-100, 100]
# Test your expression with:
# x = 104 (True)
# x = 115 (False)
# x = -106 (True)
# x = -99 (False)
x = -99
(x % 2 == 0) and ((x>=-100) or (x<=100))

# In this code, the 'and' operator is used to determine if a string stored in the variable "s" starts
# and ends with a capital letter. Index slicing and the isupper() method is used in the and statement
# to determine if this is True or False. If both statements about "s" are true, then the result is always
# going to be true.
# [ ] Write an expression to test if a string s starts and ends with a capital letter
# HINT: You might find the function `str.isupper()` useful
# Test your expression with
# s = "CapitaL" (True)
# s = "Not Capital" (False)
s = "Not Capital"
(s[0].isupper()) and (s[-1].isupper())

# In this code, an if/else statement is used to determine if a string stared in 's' contains a numerical value
# and if the value is greater than the value stored in "x". The isnumeric() method is used to determine if s
# is numeric. Then, if s is numeric, (>) is used to see if the float value of 's' is greater than the value of 'x'.
# If 's' is not numeric, then a statement saying so is displayed.
# [ ] Write an expression to test if a string s contains a numerical value
# then test if the value is greater than the value stored in x
# HINT: Use the functions `s.isnumeric()` and `float(s)`
# Test your expression with
# s = "39"
# x = 24
# Expression should yield True
# s = "a39"
# x = 24
# Expression should yield False
s = "a39"
x = 24
if s.isnumeric():
if float(s)>x:
print(s ,"is a number greater than x")
else:
print("s, is a number less than x")
else:
print (s, "doesn't contain a numerical value")

# In this code, the "and" operator is used to determine if the value of x is within the range [10,20]
# The >= and <= operators are used to achieve this. Since 11 is greater than 10 and less than 20, this code
# evaluates to True.
x = 11
(x >= 10) and (x <= 20)

# In this code, the "and" operator is used to determine if the value of x is within the range [10,20]
# The >= and <= operators are used to achieve this. Since 30 is greater than 10 and greater than 20,
# this code evaluates to False.
x = 30
(x >= 10) and (x <= 20)

# In this code, the "or" and "not" operators are used to determine if the value of x is within the range [10,20]
# If the value of x is not less than 10 or greater than 20, True will display. However if x is either less than 10 or
# greater than 20, False will display. Since 11 is not less than 10 or greater than 20, this code evaluates to True.
x = 11
not((x < 10) or (x > 20))

# In this code, the "or" and "not" operators are used to determine if the value of x is within the range [10,20]
# If the value of x is not less than 10 or greater than 20, True will display. However if x is either less than 10 or
# greater than 20, False will display. Since 30 is greater than 20, this code evaluates to False.
x = 30
not((x < 10) or (x > 20))

# In this code, the 'or' operator is used to determine if x is outside the range [10, 20].
# If x is either <= 10 or >= 20, then x is outside of range and True will display.
# If x is not <= 10 or >= 20, then x is within the range and False will display.
# [ ] Write an expression equivalent to the one below to
# test if x is outside the range [10, 20] (seen in a previous example)
# (x < 10) or (x > 20)
# Test your expression with
# x = 11 (False)
# x = 50 (True)
x = 11
(x <= 10) or (x >= 20)

# In this code, the "not", "and", and "or" operators are used to determine if x is an even number outside
# the range [-100, 100]. If x is not an odd number and is inside the range, then True wil display.
# But if x is an odd number and is inside the range, then False will display. The number has to be both
# even and outside of range for 'True' to display.
# [ ] Write a second expression to test if x is an even number outside the range [-100, 100]
# Do NOT use the expression you wrote for a previous exercise
# Test your expression with:
# x = 104 (True)
# x = 115 (False)
# x = -106 (True)
# x = -99 (False)
x = -99
not ((x % 2 != 0) and ((x > -100) or (x < 100)))

# In this code, the 'and' operator is used in an if/else statement to check if the user entered an
# odd positive number. The input is first turned into an integer using int() and then the if/else statement
# displays if the number is valid or not.
# Solicit user input
x = input("Enter an odd positive number: ")
# Convert the string input into int
x = int(x)
# Test number for validity
if ((x > 0) and (x % 2 != 0)):
print(x, "is a valid number")
else:
print(x, "is NOT a valid number")

# In this code, the 'and' operator is used in an if/else statement to display the decade the user was born
# based on the birth year entered by the user. First, the user is asked to enter the birth year. Then, if
# the year entered is less than 1970, an statement saying so will display. If the year is higher than 1970,
# an statement displaying the decade theyr were born will be displayed using the < & > in the 'and'
# statement.
# Solicit user input
y = input("Enter your birth year: ")
# Convert the string input into int
y = int(y)
# Check the decade membership
if (y < 1970):
print("You were born before 1970!")
elif (y >= 1970 and y < 1980):
print("You were born in the 70s!")
elif (y >= 1980 and y < 1990):
print("You were born in the 80s!")
elif (y >= 1990 and y < 2000):
print("You were born in the 90s!")
elif (y >= 2000 and y < 2010):
print("You were born in early 2000s!")
else:
print("You were born in the current decade!")

# In this code, the user is asked to enter a number that is out of the range [0,100]. The input is casted to an integer,
# and then with the an if/else statement, the validity of the number is checked. If the number is either less than 0
# or greater than a 100, the number is valid. If the number is within the range, the number is not valid.
# [ ] Write a program to validate that user input is outside the range [0, 100]
x = input("Enter a number less than 0 or greater than a 100:")
x = int(x)
if ((x < 0) or (x > 100)):
print(x, "is a valid number")
else:
print(x, "is not valid. It needs to be outside the range [0,100]")

# In this code, the user is asked to enter the BMI index and this is stored in the 'index' variable.
# Then using an if/else statement, the BMI category the user fall under based on the index entered is displayed.
# The 'and' operator is used with >= & <= to check if the index is under the normal or overweight category.
# [ ] Write a program to ask a user for her/his BMI index, then display the user's BMI category
index = input("Enter your BMI index: ")
index = float(index)
if (index < 18.5):
print("You're BMI is in the underweight category")
elif (index >= 18.5 and index <= 24.9):
print("You're BMI is in the normal weight category")
elif (index >= 25 and index <= 29.9):
print("You're BMI is in the overweight category")
else:
print("You're BMI is in the obese category")