Variable and Math Operators
# -- Decalre Variables
var_a = 8
var_b = 3
# -------------- Basic Math Functions ----------------
var_add = var_a + var_b
print("Addtion of", var_a, "and", var_b)
print(var_add)
var_subtract = var_a - var_b
print("Subtraction")
print(var_subtract)
var_multiply = var_a * var_b
print("Multiplication")
print(var_multiply)
var_divide = var_a / var_b
print("Division")
print(var_divide)
# ---- Exponents ---
print("Exponents")
var_numbers = var_a ** var_b
print(var_numbers)
# ----- Floor Division ----
# -- Truncates Reminders --
print("Floor Division")
var_numbers = var_a // var_b
print(var_numbers)
# ----- Modulus / Division ----
# -- Displays Only Reminders --
print("Modulus Division")
var_numbers = var_a % var_b
print(var_numbers)
#---------------------------------------------------
# -- Extra Matha Functions / not really needed --
# -- Simple Assignments --
var_c = 5
print(var_c)
#-- Unneeded --
var_c += var_a
print(var_c)
var_c*=var_a
print(var_c)
# Propper Decimal Usage $
# Inital Findings Over-Charge Customer
print('\n---Inital Findings- Overcharge Customer---')
item = .70
rate = 1.05
tax=item*rate
total=item+tax
print('{:.2f}'.format(total))
# Decimal Module Results
print('\nDecimal Module Results')
from decimal import *
item = Decimal(.70)
rate = Decimal(1.05)
tax=item*rate
total=item+tax
print('{:.2f}'.format(total))
# -- ----------------Comparison ---------------------
var_bool = var_a == var_b
print("My Checker")
print(var_bool)
var_bool = var_a != var_b
print("Not Equal")
print(var_bool)
var_bool = var_a > var_b
print("Greater Than")
print(var_bool)
var_bool = var_a < var_b
print("Less Than")
print(var_bool)
var_bool = var_a >= var_b
print("Greater Than or Equal")
print(var_bool)
var_bool = var_a <= var_b
print("Less Than or Equal")
print(var_bool)
# -------------Logical operators True and False-------------
var_logic_a = True
var_logic_b = False
print("Comares to see if you end up with a true or false")
print("Just like Binary Logic 0+0=0, 0+1=1, 1+1=1")
print(var_logic_a and var_logic_a)
print("One Side Has to be True")
print(var_logic_a or var_logic_b)
print("Flips POS NEG")
print(not var_logic_a)
# -- Same Math Logic for Priority when Using () --
var_numberval = 4*2+6
print(var_numberval)
#-- verses --
var_numberval = 4*(2+6)
print(var_numberval)
# ------------ Global vs Local Variables ------------
x = 20 # Creaed Outside Function (Global)
def my_function():
y=24 # Local only to the function
global x # Define as Global Variable
x+=25
my_function()
print(x) # Output: 30
print(y) # Output Error
import math,random
# Rounding Up/Down Math Functions
print(math.ceil(9.4)) # Rounds Down
print(math.floor(9.4)) # Rounds Up
print(math.pow(8,2)) # Exponential
print(math.sqrt(64)) # Square Root
print(random.sample(range(1,100),1)) # Single Random
print(random.sample(range(1,100),5))#Multiple Randoms