#John Bible 12/10/21
#What I learned is how to document code
#What I had trouble with was understanding what classified as an argument but I overcame this by doing my best with the definition given.
def C2F(degrees_celsius):
""" Convert Celsius to Fahrenheit"""
return degrees_celsius * (9/5) + 32
print("Accessing docstrings using __doc__:\n")
print(C2F.__doc__)
def C2F(degrees_celsius):
""" Convert Celsius to Fahrenheit"""
return degrees_celsius * (9/5) + 32
print("Accessing docstrings using help:\n")
help(C2F)
def kg2lb(kilograms):
"""
Convert kilograms to pounds
args:
kilograms: weight in kg
returns:
pounds: weight in lb
"""
pounds = kilograms * 2.20462262185
return pounds
print("Accessing docstrings using __doc__:\n")
print(kg2lb.__doc__)
def kg2lb(kilograms):
"""
Convert kilograms to pounds
args:
kilograms: weight in kg
returns:
pounds: weight in lb
"""
pounds = kilograms * 2.20462262185
return pounds
print("Accessing docstrings using help:\n")
help(kg2lb)
# [ ] The following function generates a single die roll
# Document the function using a one-line docstring
#This will Document the function using a one-line docstring
from random import randint
def die_roller ():
"""Return number between 1 and 6. """
return (randint(1, 6))
# [ ] The following function computes the area of a circle
# Document the function using a one-line docstring
#This will Document the function using a one-line docstring
from math import pi
def circle_area(r):
"""Return r squared times pi. """
return pi * (r ** 2)
# [ ] The following program counts the number of times the value in `a` appears in `lst`
# Document the function using a multi-line docstring
#This will Document the function using a multi-line docstring
def count_occurrences(a, lst):
"""
Count number of times a value occurs.
args:
lst: list of elements
returns:
count: number of times a value occurs
Errors:
IndentationError:unindent does not match any outer indentation level
"""
count = 0
for element in lst:
if a == element:
count = count + 1
return count
# [ ] The following program prints out the date `d` number of days after today
# Document the function using a multi-line docstring
#This will Document the function using a multi-line docstring
from datetime import date, timedelta
def future_date(d):
"""
Print a future date.
errors:
IndentationError:unindent does not match any outer indentation level
"""
today = date.today()
td = timedelta(days = d)
future = today + td
print("Date {:d} from today is: {:s}".format(d, future.strftime("%a %h %d, %Y")))
# Date 10 days from today
future_date(10)