
import time



# Example 1
print("**** Start Example 1 *****")
def get_full_name(f_name, l_name="James"):
    """
    An example of keyword parameters.

    :param f_name:
    :param l_name:
    :return: full_name
    """
    if not l_name:
        l_name = ""

    full_name = f_name + " " + l_name

    return full_name


full_n = get_full_name('Admas', "Kin")
print full_n

full_n = get_full_name('Admas', l_name="bob")
print full_n

full_n = get_full_name(f_name='ak', l_name="bob")
print full_n

# Error example (Uncomment to run and see the error)
# full_n = get_full_name(f_name='ak', "bob")
# print full_n
print("**** End Example 1 *****")




# Example 2
print("**** Start Example 2 *****")
def calculare_area(width=0, height=0):
    """
    Example function of keyword parameters.

    :param width:
    :param height:
    :return: area
    """
    if not width or not height:
        raise ValueError("Width and height can not be 0")

    area = width * height

    return area

print calculare_area(4,2)
print calculare_area(4)

print("**** End Example 2 *****")


# Example 3
print("**** Start Example 3 *****")
def verify_process_is_complete(type_of_process, max_retry=10, time_to_sleep=2):
    """
    Function that will implement a retry logic using for loop.

    :param type_of_process:
    :param max_retry:
    :param time_to_sleep:
    :return: None
    """

    print("Verifying the process '{}' is complete.".format(type_of_process))

    completed = False
    for i in xrange(1, max_retry):
        print("Attempt number: {}".format(i))

        # code
        # if i == 6:
        #     completed = True

        if completed == True:
            print "The process is complete. Stopping rechecking."
            break
        else:
            print "The process is not complete. Sleeping for {} seconds and retrying.".format(time_to_sleep)
            time.sleep(2)

    if not completed:
        raise Exception("The process is did not complete after waiting for '{}' seconds.".format(max_retry * time_to_sleep))

    else:
        return None

# verify_process_is_complete('bla')
verify_process_is_complete('bla', time_to_sleep=1)

print("**** End Example 3 *****")


