5.20. Functions Write Code Questions¶
Write a function called
remainder
that takes in parametersx
andy
(wherey
defaults to 4) and returns the remainder ofx
divided byy
. Ignore cases for whenx
is negative ory
is less than or equal to 0. For example,remainder(5)
should return1
.Write a function called
remainder
that takes in parametersx
andy
(wherey
defaults to 4) and returns the remainder ofx
divided byy
. Ignore cases for whenx
is negative ory
is less than or equal to 0. For example,remainder(5)
should return1
.-
Write a function called
area_of_rect
that takes in parameterswidth
andlength
and returns the area (of the rectangle). For example,area_of_rect(5,4)
should return20
. Write a function called
welcome_message
that takes in a parametername
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 parametername
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
birthday
that 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
address
that combines 3 different string address parameters (city
,state
, andzip
) and returns a user’s address. After thecity
andstate
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
, andzip
) and returns a user’s address. After thecity
andstate
inputs, add a comma and a space. For example,address('Seattle', 'WA', '98105')
should return"Seattle, WA, 98105"
.-
Write a function called
squareArea
that takes in a parameterlength
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."
. Write three functions called
addNumbers
,subtractNumbers
, andcalculate
. The functionaddNumbers
should take two numbers (x
andy
) as parameters and return the value of adding them together, whilesubtractNumbers
should also take two numbers (x
andy
) and return the value ofx
minusy
. Lastly, define a function calledcalculate
that takes three numbers (a
,b
, andc
) and usesaddNumbers
andsubtractNumbers
to adda
andb
and subtractc
. The value should be returned. For example,calculate(2,3,4)
should return1
.Write three functions called
addNumbers
,subtractNumbers
, andcalculate
. The functionaddNumbers
should take two numbers (x
andy
) as parameters and return the value of adding them together, whilesubtractNumbers
should also take two numbers (x
andy
) and return the value ofx
minusy
. Lastly, define a function calledcalculate
that takes three numbers (a
,b
, andc
) and usesaddNumbers
andsubtractNumbers
to adda
andb
and subtractc
. The value should be returned. For example,calculate(2,3,4)
should return1
.