5.20. Functions Write Code Questions¶
Write a function called
remainderthat takes in parametersxandy(whereydefaults to 4) and returns the remainder ofxdivided byy. Ignore cases for whenxis negative oryis less than or equal to 0. For example,remainder(5)should return1.Write a function called
remainderthat takes in parametersxandy(whereydefaults to 4) and returns the remainder ofxdivided byy. Ignore cases for whenxis negative oryis less than or equal to 0. For example,remainder(5)should return1.-
Write a function called
area_of_rectthat takes in parameterswidthandlengthand returns the area (of the rectangle). For example,area_of_rect(5,4)should return20. Write a function called
welcome_messagethat takes in a parameternameand 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_messagethat takes in a parameternameand 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
birthdaythat takes in three parameters (month,day, andyear) and returns it in the formatmonth/day/year. For example,birthday(11, 17, 1990)should return"11/17/1990"andbirthday(7, 5, 2004)should return"7/5/2004". Write a function called
addressthat combines 3 different string address parameters (city,state, andzip) and returns a user’s address. After thecityandstateinputs, add a comma and a space. For example,address('Seattle', 'WA', '98105')should return"Seattle, WA, 98105".Write a function called
addressthat combines 3 different string address parameters (city,state, andzip) and returns a user’s address. After thecityandstateinputs, add a comma and a space. For example,address('Seattle', 'WA', '98105')should return"Seattle, WA, 98105".-
Write a function called
squareAreathat takes in a parameterlengthand 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.". Write three functions called
addNumbers,subtractNumbers, andcalculate. The functionaddNumbersshould take two numbers (xandy) as parameters and return the value of adding them together, whilesubtractNumbersshould also take two numbers (xandy) and return the value ofxminusy. Lastly, define a function calledcalculatethat takes three numbers (a,b, andc) and usesaddNumbersandsubtractNumbersto addaandband subtractc. The value should be returned. For example,calculate(2,3,4)should return1.Write three functions called
addNumbers,subtractNumbers, andcalculate. The functionaddNumbersshould take two numbers (xandy) as parameters and return the value of adding them together, whilesubtractNumbersshould also take two numbers (xandy) and return the value ofxminusy. Lastly, define a function calledcalculatethat takes three numbers (a,b, andc) and usesaddNumbersandsubtractNumbersto addaandband subtractc. The value should be returned. For example,calculate(2,3,4)should return1.