Learning Modules, Arguments, Parameters (imma noob)
Denis McMahon
denismfmcmahon at gmail.com
Fri Sep 25 19:59:38 EDT 2015
On Fri, 25 Sep 2015 12:03:43 -0700, Cody Cox wrote:
> #Design a modular program that asks the user to enter a distance in
> kilometers and then covert it to miles # Miles = Kilometers * 0.6214
#!/usr/bin/python
# main calls the input routine to get the km value, then
# calls the conversion routine to convert the km value
# to miles, then prints the output
def main():
km = get_kms()
mi = convert_km_mi(k)
print "{} Km is {} miles.".format(km, mi)
# get_float_input() reads a float input using the supplied
# prompt.
def get_float_input(prompt):
return float(input(prompt))
# Get kms uses the generic get_float_input to read a km
# value
def get_kms():
return get_float_input("Enter Kms: ")
# generic conversion function
def convert_float_a_b(a, factor):
return float(a * factor)
# convert km_mi uses the generic converter
# to convert km to miles
def convert_km_mi(km):
return convert_float_a_b(km, 0.6214)
# now call main to kick it all off
main()
--
Denis McMahon, denismfmcmahon at gmail.com
More information about the Python-list
mailing list