Learning Modules, Arguments, Parameters (imma noob)

alister alister.nospam.ware at ntlworld.com
Fri Sep 25 12:42:59 CEST 2015


On Thu, 24 Sep 2015 11:45:06 -0700, codywcox wrote:

> I seem to be having a problem understanding how arguments and parameters
> work, Most likely why my code will not run.
> Can anyone elaborate on what I am doing wrong?
> 
> '''
> Cody Cox 9/16/2015 Programming Exercise 1 - Kilometer Converter Design a
> modular program that asks the user to enter a distance in kilometers and
> then convert it to miles Miles = Kilometers * 0.6214 '''
> 
> def main():
>    get_input()
>    convert_kilo()
> 
> 
>  def get_input(kilo):
>    kilo = float(input('Enter Kilometers: '))
>    return kilo
> 
>  def convert_kilo(kilo,miles):
>      miles = float(kilo * 0.6214)
>      print( kilo,' kilometers converts to ',miles,' miles')
> 
>  main()

clearly a homework exercise but you  have asked for help in understanding 
& not just for a solution which is good.

as others have pointed out you are throwing away the data returned from 
get_input

I would also suggest that you return the result form convert_kilo instead 
of printing it in the function & print it in the main loop instead.

kilo=get_input()
miles=convert_kilo(kilo)
print (miles)

it does not matter for this trivial assignment but as you progress 
further you will discovery it is better to keep output seperated from the 
main logic of the program. 



-- 
What is mind?  No matter.  What is matter?  Never mind.
		-- Thomas Hewitt Key, 1799-1875


More information about the Python-list mailing list