Wrote the functions for the programming assignment