#!/usr/bin/env python3 
################################################################################### 
# Create your own functions 
################################################################################### 
print("Content-Type: text/html \n")     #http header with newline char (required for the web)
print('<pre>')                          #to produce better display on the web 

from datetime import datetime
import random
import math
  
#------------------------------------------------------------------------------- 
# function printGreeting - does not receive parameters
#                        - does not return a value
#------------------------------------------------------------------------------- 
def printGreeting():                          #define printGreeting function 
 
    now = datetime.now( )                     #get the current date and time 
 
    if now.hour < 12 :                        #are hours < 12 
        print("Good Morning -- ") 
    else : 
        print("Good Afternoon -- ") 
 
    print("the date/time is now " , now )
#   print("the date/time is now " , now.strftime('%m/%d/%Y %H:%M:%S %z') )   #or print(it by components 
                
 
#------------------------------------------------------------------------------- 
# function odd_even - receives 2 parameters
#                   - does not return a value
#------------------------------------------------------------------------------- 
def odd_even(min, max):                      #function that accepts 2 parameters 
 
    rand  = random.randint(min, max)         #rand number from min to max 
 
    rem   = rand % 2                         #the remainder of 2 
    which = 'even' if (rem == 0) else 'odd'  #is it odd or even? 
 
    print("The number ", rand, " is ", which)    
 
#------------------------------------------------------------------------------- 
# function future_value - receives 3 parameters (year is optional)
#                       - returns a value
#------------------------------------------------------------------------------- 
def future_value(amt, int, year=15):         #function that accepts 3 parameters 
                                             #year is optional.  default=15
 
    int1 = 1 + int/100                       #1 + the interest rate 
    fv   = amt * math.pow(int1, year)        #future value of an amount 
 
    return (fv)                              #return the future value    
 
#=============================================================================== 
# Call the functions
#=============================================================================== 
print("Create and Call Custom Functions") 
print() 

print("Our first function - the current date/time") 
printGreeting( )                                #call printGreeting function 
print()         

print("Our second function - Odd or Even? ") 
odd_even(1,100)                                 #call function and pass 2 arguments 
print()  
 
print("Our third function - future value") 

amount = random.randint(100,5000)               #random from 100 to 5000 
int    = random.randint(200,800) / 100.0        #interest from 2.00 to 7.99
years  = random.randint(1,10)                   #random from 1 to 10 
 
value  = future_value(amount, int, years)       #pass and receive data 
 
formatted = F"${value:0,.2f}"                   #formatted with commans and 2 decimal places
 
print("The future value of $", amount, "@", int, "% interest for", years, "years") 
print("is:", formatted) 
print()