Learning Modules, Arguments, Parameters (imma noob)
Joel Goldstick
joel.goldstick at gmail.com
Thu Sep 24 15:15:06 EDT 2015
On Thu, Sep 24, 2015 at 2:45 PM, <codywcox at gmail.com> 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()
>
Change the above call to:
kilos = get_input()
This is because your function returns that value
> convert_kilo()
>
This one you need to pass the kilos argument, and you don't need to pass
the miles parameter (see below)
convert_kilo(kilos)
>
>
> def get_input(kilo):
>
You defined get_input with no parameters, so it gets no arguments when you
call it:
def get_input():
> kilo = float(input('Enter Kilometers: '))
> return kilo
>
> def convert_kilo(kilo,miles):
>
Make the above:
def convert_kilo(kilo):
> miles = float(kilo * 0.6214)
> print( kilo,' kilometers converts to ',miles,' miles')
>
> main()
>
When you define a function, the names between the parentheses are called
parameters. When you call the function, they are called arguments. They
need to match. When you return a value from a function, you need to put a
name to it, or it is lost.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150924/275755fb/attachment.html>
More information about the Python-list
mailing list