Skip to content

Instantly share code, notes, and snippets.

@rubycarefree
rubycarefree / CodeStyle_Answer_Python
Created August 9, 2022 15:10
This function to calculate the area of a rectangle is not very readable. Can you refactor it, and then call the function to calculate the area with base of 5 and height of 6? Tip: a function that calculates the area of a rectangle should probably be called rectangle_area, and if it's receiving base and height, that's what the parameters should b…
def rectangle_area(base, height):
area = base * height
print("The area is " + str(area))
rectangle_area(5,6)
@rubycarefree
rubycarefree / CodeReuse_Answer_Python
Created August 9, 2022 15:08
In this code, identify the repeated pattern and replace it with a function called month_days, that receives the name of the month and the number of days in that month as parameters. Adapt the rest of the code so that the result is the same. Confirm your results by making a function call with the correct parameters for both months listed.
def month_days(month, days):
print(month, "has", days, "days.")
month_days("June","30")
month_days("July","31")