# Course: IT1 1120
# Assignment Number 1
# Family name, Given Name: Cummings, Emma
# Student number:  7671575


###################################################################
# Question 1
###################################################################

def pythagorean_pair(a,b):
    '''(int, int) -> bool
    Takes two integers a and b as input and returns True if a and b are pythagorean pair and False otherwise.
    Two numbers a and b are called pythagorean pair if both a and b are integers and there exists an integer c such that (a**2) + (b**2) = (c**2).'''
    import math
    c = math.sqrt((a**2) + (b**2))
    return (c % 1 == 0 and type (b) == int and type (a) == int)

###################################################################
# Question 2
###################################################################

def mh2kh(s):
    ''' (number) -> number
    Given speed (s) expressed in miles per hour, will return the speed in kilometers per hour.
    '''
    km = s * 1.60934
    return km

###################################################################
# Question 3
###################################################################
def in_out(xs, ys, side):
    '''(number, number, number) -> None
    Side must be non-negative.
    Takes three numbers, coordinates xs and ys at the bottom left corner of a square, and the length of the sides of a square.
    Prompts user to enter two numbers, coordinates of a point. Prints True if the given query point is inside the given square and False if otherwise.
    '''
    x = float(input("Enter a number for the x coordinate of a query point: "))
    y = float(input("Enter a number for the x coordinate of a query point: "))
    print (str((xs + side) >= x >= xs and (ys + side) >= y >= ys))

###################################################################
# Question 4
###################################################################

def safe(n):
    '''(integer) -> bool
    n must be non-negative.
    The function determines if n contains a 9 as a digit, or if it can be divided by 9.
    Returns True if n is does not contain 9 or is divisible by 9 and False otherwise.'''
    return n % 9 != 0 and round(n/10) != 9 and n%10 != 9

###################################################################
# Question 5
###################################################################

def quote_maker(quote, name, year):
    '''(str, str, int) -> str
    A quote formatter than returns a string displaying the quote, name and year.
    '''
    return "In " + str(year) + ", a person called " + name + ' said: "' + quote + '"'

###################################################################
# Question 6
###################################################################
def quote_displayer():
    '''(None) -> None
    Runs user input of quote, name and year through the function quote_maker and prints the result.
    '''
    quote = input('Give me a quote: ')
    name = input('Who said that? ')
    year = input('What year did she/he say that? ')
    print (quote_maker(quote,name,year))

###################################################################
# Question 7
###################################################################

def rps_winner():
    '''(None) -> None
    Determines the winner of a rock, paper, scissors game with rock, paper or scissors inputted by the user.
    Prints the result as "Player 1 wins. That is True/False. IT is a tie. That is not True/False"
    '''
    player1 = input('What choice did player 1 make? \n Type one of the following options: rock, paper, scissors: ')
    player2 = input('What choice did player 2 make? \n Type one of the following options: rock, paper, scissors: ')
    player1win = ((player1 == "rock" and player2 == "scissors") or (player1 == "paper" and player2 == "rock") or (player1 == "scissors" and player2 == "paper"))
    tie = (player1 == player2)
    #assignment did not specify whether to print or return.
    print("Player 1 wins. That is " + str(player1win) + "\nIt is a tie. That is not " + str(tie == False))

###################################################################
# Question 8
###################################################################
def fun(x):
    '''(Number) -> Number
    x must be a positive number.
    Function solves the following equation and returns y:
    104**y == x+3 '''
    import math
    y = math.log10(x + 3) / 4
    return y

###################################################################
# Question 9
###################################################################
def ascii_name_plaque(name):
    ''' (str) -> None
    Creates a formatted name plaque.
    '''
    linea = "****"+len(name)*"*"+"****\n"
    lineb = "*   "+len(name)*" "+"   *\n"
    linec = "* __" + name + "__ *\n"
    print( linea + lineb + linec + lineb + linea)

###################################################################
# Question 10 barely started
###################################################################
def draw_car():
    ''' (None) -> None
    Draws a car using turtle graphics.
    '''
    import turtle

    s=turtle.Screen()
    t=turtle.Turtle()


    #  # draw right eye as a rectangle
    t.up()
    t.goto(-70,0)
    t.pendown()
    t.forward(40)
    t.left(60)
    t.forward(50)
    t.right(60)
    t.forward(60)
    t.right(60)
    t.forward(50)
    t.left(60)
    t.forward(50)
    t.backward(200)
    t.forward(200)
    t.color('pink')
    t.begin_fill()
    t.right(90)
    t.forward(30)
    t.right(90)
    t.forward(200)
    t.setheading(90)
    t.forward(30)
    t.setheading(0)
    t.forward(200)
    t.end_fill()
    t.color('black')
    t.right(90)
    t.forward(30)
    t.right(90)
    t.forward(200)
    t.setheading(90)
    t.forward(30)
    t.setheading(0)
    t.forward(200)
    t.right(90)
    t.forward(30)
    t.right(90)

    t.setheading(0)
    t.color('gray')
    t.begin_fill()
    t.forward(5)
    t.setheading(270)
    t.forward(5)
    t.setheading(180)
    t.forward(210)
    t.setheading(90)
    t.forward(5)
    t.setheading(0)
    t.forward(5)
    t.end_fill()
    #finished bumper
    t.color('black')
    t.penup()
    t.forward(200)
    t.setheading(180)

    # finished car outline
    t.forward(40)
    t.setheading(90)
    t.begin_fill()
    t.pendown()
    t.circle(20,360)
    t.penup()
    t.end_fill()
    t.circle(20,180)
    t.setheading(180)
    t.forward(50)
    t.setheading(90)
    t.begin_fill()
    t.pendown()
    t.circle(20,360)
    t.penup()
    t.end_fill()
    t.circle(20,180)
    t.setheading(180)
    t.forward(30)
    t.setheading(90)
    t.forward(30)
    t.right(90)
    t.forward(200)
    # finished tires
    #

    t.setheading(180)
    t.forward(120)
    t.setheading(90)
    t.pendown()
    t.forward(43.30127019)
    t.setheading(270)
    t.forward(43.30127019+30)
    t.penup()
    #finished window and door
    t.setheading(90)
    t.forward(30)
    t.setheading(0)
    t.forward(70)
    t.setheading(270)
    t.pendown()
    t.forward(13.5)
    t.penup()
    t.backward(13.5)
    t.setheading(180)
    t.forward(70)
    t.setheading(270)
    t.forward(30)
    t.setheading(0)
    t.backward(80)
    #start at bottem left corner facing right

    #finished car bumper
    t.penup()
    t.forward(40)
    t.pendown()
    t.setheading(270)
    t.color('gray')
    t.begin_fill()
    t.circle(10,360)
    t.end_fill()
    t.circle(10,180)
    t.color('black')
    t.setheading(180)
    t.penup()
    t.forward(8)
    t.pendown()
    t.setheading(90)
    t.circle(2,540)
    t.penup()
    t.setheading(0)
    t.forward(2)
    #draw hubcaps
    t.setheading((360/5) * 0 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    t.setheading((360/5) * 1 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    t.setheading((360/5) * 2 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    t.setheading((360/5) * 3 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    t.setheading((360/5) * 4 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    # finished window
    t.setheading(0)
    t.forward(20 + 50)
    # t.forward(50)


    t.penup()
    t.forward(10)
    t.pendown()
    t.setheading(270)
    t.color('gray')
    t.begin_fill()
    t.circle(10,360)
    t.end_fill()
    t.circle(10,180)
    t.color('black')
    t.setheading(180)
    t.penup()
    t.forward(8)
    t.pendown()
    t.setheading(90)
    t.circle(2,540)
    t.penup()
    t.setheading(0)
    t.forward(2)

    t.setheading((360/5) * 0 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    t.setheading((360/5) * 1 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    t.setheading((360/5) * 2 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    t.setheading((360/5) * 3 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)
    t.setheading((360/5) * 4 + 90)
    t.forward(2)
    t.pendown()
    t.forward(6)
    t.penup()
    t.backward(8)

    t.setheading(0)
    t.forward(20 + 40)
    t.setheading(90)
    t.forward(25)
    t.setheading(180)
    t.forward(5)
    t.pendown()
    t.color('white')
    t.begin_fill()
    t.forward(5)
    t.setheading(90)
    t.forward(3)
    t.setheading(0)
    t.forward(5)
    t.setheading(270)
    t.forward(3)
    t.end_fill()
    t.penup()

    t.setheading(180)

    t.forward(100)

    t.pendown()
    t.color('gray')
    t.begin_fill()
    t.forward(5)
    t.setheading(90)
    t.forward(3)
    t.setheading(0)
    t.forward(5)
    t.setheading(270)
    t.forward(3)
    t.end_fill()
    t.penup()

    t.setheading(180)

    t.forward(85)

    t.pendown()
    t.color('white')
    t.begin_fill()
    t.forward(5)
    t.setheading(90)
    t.forward(3)
    t.setheading(0)
    t.forward(5)
    t.setheading(270)
    t.forward(3)
    t.end_fill()
    t.penup()
    t.hideturtle()

    s.exitonclick()
###################################################################
# Question 11
###################################################################
def alogical(n):
    '''(number) -> int
    n must be bigger than or equal to 1.
    Determines how many times n must be divided by 2 to be smaller than or equal to 1.
    '''
    import math
    return math.ceil(math.log(n,2))

###################################################################
# Question 12
###################################################################
def time_format(h,m):
    '''(int, int) -> str
    h must be in the range 0 to 23, m must be in the range 0 to 59.
    Returns the time rounded to the nearest 5 minutes in minutes-to or minutes-past form.
    '''
    m = int(5 * round(float(m)/5))
    if m == 60:
        m = 0
        h = h + 1
    if h == 24:
        h = 0
    if m == 0:
        time = str(h) + " o'clock"
    elif m < 30:
        time = str(m) + " minutes past " + str(h) + " o'clock"
    elif m == 30:
        time = "Half past " + str(h) + " o'clock"
    else:
        h=h+1
        if h == 24:
            h = 0
        time = str(60-m) + " minutes to " + str(h) + " o'clock"

    return time

###################################################################
# Question 13
###################################################################
def cad_cashier(price,payment):
    '''(float,float) -> float
    Payment must be larger than Price.
    Returns the amount of change a cashier should give after rounding to the nearest 5 cents.
    '''
    change = payment - price
    change = round(.05 * round(change/.05),2)
    return change

###################################################################
# Question 14
###################################################################
def min_CAD_coins(price,payment):
    '''(float,float) -> int, int, int, int, int
    Payment must be larger than Price.
    Returns the minimum coins in each denomination required to repay the amount of change.
    '''
    change = cad_cashier(price,payment)
    change = round(change * 100)
    t = int(change // 200)
    change = change - (t * 200)
    l = int(change // 100)
    change = change - (l * 100)
    q = int(change // 25)
    change = change - (q * 25)
    d = int(change // 10)
    change = change - (d * 10)
    n = int(change // 5)
    return (t,l,q,d,n)
