5.20. Functions Write Code Questions

  1. Write a function called remainder that takes in parameters x and y (where y defaults to 4) and returns the remainder of x divided by y. Ignore cases for when x is negative or y is less than or equal to 0. For example, remainder(5) should return 1.

    Write a function called remainder that takes in parameters x and y (where y defaults to 4) and returns the remainder of x divided by y. Ignore cases for when x is negative or y is less than or equal to 0. For example, remainder(5) should return 1.

  2. Write a function called area_of_rect that takes in parameters width and length and returns the area (of the rectangle). For example, area_of_rect(5,4) should return 20.

  3. Write a function called welcome_message that takes in a parameter name and returns "Hello (name)! We hope that you will enjoy this course. :)". For example, welcome_message('Aurora') should return "Hello Aurora! We hope that you will enjoy this course. :)".

    Write a function called welcome_message that takes in a parameter name and returns "Hello (name)! We hope that you will enjoy this course. :)". For example, welcome_message('Aurora') should return "Hello Aurora! We hope that you will enjoy this course. :)".

  4. Write a function called birthday that takes in three parameters (month, day, and year) and returns it in the format month/day/year. For example, birthday(11, 17, 1990) should return "11/17/1990" and birthday(7, 5, 2004) should return "7/5/2004".

  5. Write a function called address that combines 3 different string address parameters (city, state, and zip) and returns a user’s address. After the city and state inputs, add a comma and a space. For example, address('Seattle', 'WA', '98105') should return "Seattle, WA, 98105".

    Write a function called address that combines 3 different string address parameters (city, state, and zip) and returns a user’s address. After the city and state inputs, add a comma and a space. For example, address('Seattle', 'WA', '98105') should return "Seattle, WA, 98105".

  6. Write a function called squareArea that takes in a parameter length and calculates the area of the square. It returns a string with this format: “The total area of the square with length (length) is (area).”. For example, squareArea(10) would return "The total area of the square with length 10 is 100.".

  7. Write three functions called addNumbers, subtractNumbers, and calculate. The function addNumbers should take two numbers (x and y) as parameters and return the value of adding them together, while subtractNumbers should also take two numbers (x and y) and return the value of x minus y. Lastly, define a function called calculate that takes three numbers (a, b, and c) and uses addNumbers and subtractNumbers to add a and b and subtract c. The value should be returned. For example, calculate(2,3,4) should return 1.

    Write three functions called addNumbers, subtractNumbers, and calculate. The function addNumbers should take two numbers (x and y) as parameters and return the value of adding them together, while subtractNumbers should also take two numbers (x and y) and return the value of x minus y. Lastly, define a function called calculate that takes three numbers (a, b, and c) and uses addNumbers and subtractNumbers to add a and b and subtract c. The value should be returned. For example, calculate(2,3,4) should return 1.

You have attempted of activities on this page