CMU 15-112 Summer 2019: Fundamentals of Programming and Computer Science
Homework 1-1 (Due Tue 2-Jul, at 5pm)




  1. distance(x1, y1, x2, y2) [5 pts]
    Write the function distance(x1, y1, x2, y2) that takes four int or float values x1, y1, x2, y2 that represent the two points (x1, y1) and (x2, y2), and returns the distance between those points as a float.

  2. isRightTriangle(x1, y1, x2, y2, x3, y3) [25pts]
    Write the function isRightTriangle(x1, y1, x2, y2, x3, y3) that takes 6 int or float values that represent the vertices (x1,y1), (x2,y2), and (x3,y3) of a triangle, and returns True if that is a right triangle and False otherwise. Remember to use almostEqual (instead of ==) when comparing floats!
    Hint: you should use the distance function that you just wrote to help you solve this problem!

  3. getKthDigit(n, k) [35pts]
    Write the function getKthDigit(n, k) that takes a possibly-negative int n and a non-negative int k, and returns the kth digit of n, starting from 0, counting from the right. So:
       getKthDigit(789, 0) returns 9
       getKthDigit(789, 2) returns 7
       getKthDigit(789, 3) returns 0
       getKthDigit(-789, 0) returns 9

  4. isPerfectSquare(n) [35pts]
    Write the function isPerfectSquare(n) that takes a possibly-non-int value, and returns True if it is an int that is a perfect square (that is, if there exists an integer m such that m**2 == n), and False otherwise. Do not crash on non-ints nor on negative ints.