# Author:
# Date: 11/7/25
# CSCI 141 Exam 2, Fall 2025

""" There are four functions to implement, plus a main program at the bottom
of this file. The main program prints one number, making use of the sixes and
sixes_to functions. I recommend implementing things in the following order:
1. sixes (5 points)
2. sixes_to (5 points, relies on sixes)
3. main program (2 points, relies on sixes and/or sixes_to)
4. triangle (6 points)
5. change (2 points)
"""

def sixes(n):
    """ Return True if n is divisible by 6 and has 6 as its last digit.
    Precondition: n is a positive integer.
    
    Examples:
    >>> sixes(6)   => True
    >>> sixes(36)  => True
    >>> sixes(16)  => False
    >>> sixes(12)  => False
    >>> sixes(156) => True
    """
    return (n % 6 == 0) and (n % 10 == 6)



def sixes_to(n):
    """ Return the number of integers between 1 and n (inclusive) that are
    divisible by 6 and end in 6.
    >>> sixes_to(1)   => 0
    >>> sixes_to(6)   => 1
    >>> sixes_to(66)  => 3
    >>> sixes_to(156) => 6
    >>> sixes_to(9006) => 301 """
    count = 0
    for i in range(1, n+1):
        if sixes(i):
            count += 1
    return count


def triangle(height):
    """ Print a text drawing of a right triangle with the given height. The
    base is the same length as the height (in characters), though it will not
    look isosceles because the printed characters are rectagular, not square.
    Precondition: height >= 2. An example:
    >>> triangle(5)
    #
    ##
    # #
    #  #
    #####
    
    More examples:
    triangle(2)  triangle(4)    triangle(8)
    #            #              #
    ##           ##             ##
                 # #            # #
                 ####           #  #
                                #   #
                                #    #
                                #     #
                                ########
    """
    print("")
    
    for row in range(1,height-1):
        spaces = row-1
        print("#", " " * spaces, "#", sep="")
    
    print("#"*height)
    
    
def change(cents_owed, dollars, quarters, dimes, nickels, pennies):
    """ Calculate the correct number of each coin to return as change for a
    vending machine transaction. The arguments are as follows:
    - cents_owed: the integer number of cents the purchaser owes
    - remaining arguments: the integer number of each currency inserted
    
    The total amount returned makes correct change - the amount inserted minus
    the cents owed. You may assume that the amount inserted exceeds cents_owed.
    
    The machine returns only coins (no $1 bills). This function calculates the
    amount of each coin to return to make correct change; it returns four
    values: quarters_out, dimes_out, nickels_out, and pennies_out, each
    representing the integer number of the given coin to return.
    
    The coins returned should be as large as possible: return quarters until
    the amount owed is less than 25 cents, then return dimes until the amount
    is less than 10 cents, and so on. Partial credit will be given for returning
    correct change but with other combinations of coins.
    
    Examples:
    >>> change(100, 0, 5, 0, 0, 0)    # $1 owed, 5 quarters inserted
    (1, 0, 0, 0)                      # 1 quarter returned
    >>> change(100, 1, 0, 0, 0, 0)    # $1 owed, $1 inserted
    (0, 0, 0, 0)                      # no change
    >>> change(189, 2, 0, 0, 0, 0)    # $1.89 owed, $2 inserted
    (0, 1, 0, 1)                      # 1 dime, 1 penny ($0.11) returned
    >>> change(132, 2, 0, 0, 0, 1)    # $1.32 owed, $2.01 inserted
    (2, 1, 1, 4)                      # 2 quarters, 1 dime, 1 nickel, 4 pennies ($0.69) returned
    """
    # cents_owed, dollars, quarters, dimes, nickels, pennies
    cents_given = (100*dollars) + (25*quarters) + (10*dimes) + (5*nickels) + pennies
    
    change = cents_given - cents_owed
  
    quarters_out = change // 25
    change %= 25
    
    dimes_out = change // 10
    change %= 10
    
    nickels_out = change // 5
    
    pennies_out = change % 5
    return quarters_out, dimes_out, nickels_out, pennies_out

    # return (0, 0, 0, change)


""" Main program
Given two positive integer command line arguments a and b with a < b,
print the number of integers between a and b (inclusive) that are
divisible by 6 and end in 6.
    
    Hint: the number of such integers between a and b can be found by
    finding the number between 1 and b, and then subtracting the number
    that are less than a.

Examples:
>>> %Run exam2.py 1 6
0
>>> %Run exam2.py 1 66
3
>>> %Run exam2.py 10 100
3
>>> %Run exam2.py 100 156
2
>>> %Run exam2.py 1 9006
301

Write your main program here; be sure to put your code inside a main guard:"""
