Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97086
| Subject | Re: Learning Modules, Arguments, Parameters (imma noob) |
|---|---|
| References | <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> |
| From | MRAB <python@mrabarnett.plus.com> |
| Date | 2015-09-24 20:25 +0100 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.141.1443122761.28679.python-list@python.org> (permalink) |
On 2015-09-24 19:45, codywcox@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
> '''
>
First of all, it looks like your indentation is slightly off because
"def main" line is that the left margin and the other 2 "def" lines and
the "main()" line aren't.
> def main():
You're not passing anything into 'get_input', neither are you saving
any result that it might be returning.
> get_input()
You're not passing anything into 'convert_kilo'.
> convert_kilo()
>
>
You're defining 'get_input' to accept 1 parameter 'kilo'. Why? You're
assigning to 'kilo' in the first line, so any value you _did_ pass in
would be ignored.
> def get_input(kilo):
> kilo = float(input('Enter Kilometers: '))
> return kilo
>
You're defining 'convert_kilo' to accept 2 parameters. You're using the
'kilo' parameter, but not the 'miles' parameter because you're
assigning to it on the first line, so any value you _did_ pass in would
be ignored.
> def convert_kilo(kilo,miles):
'kilo' is already a float, and you're multiplying it by a float, so the
'float' call is pointless.
> miles = float(kilo * 0.6214)
> print( kilo,' kilometers converts to ',miles,' miles')
>
> main()
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Learning Modules, Arguments, Parameters (imma noob) codywcox@gmail.com - 2015-09-24 11:45 -0700
Re: Learning Modules, Arguments, Parameters (imma noob) MRAB <python@mrabarnett.plus.com> - 2015-09-24 20:25 +0100
Re: Learning Modules, Arguments, Parameters (imma noob) John Gordon <gordon@panix.com> - 2015-09-24 19:32 +0000
Re: Learning Modules, Arguments, Parameters (imma noob) Larry Hudson <orgnut@yahoo.com> - 2015-09-24 13:27 -0700
Re: Learning Modules, Arguments, Parameters (imma noob) alister <alister.nospam.ware@ntlworld.com> - 2015-09-25 10:42 +0000
Re: Learning Modules, Arguments, Parameters (imma noob) Cody Cox <codywcox@gmail.com> - 2015-09-25 11:50 -0700
Re: Learning Modules, Arguments, Parameters (imma noob) Laura Creighton <lac@openend.se> - 2015-09-25 22:15 +0200
Re: Learning Modules, Arguments, Parameters (imma noob) Laura Creighton <lac@openend.se> - 2015-09-25 22:25 +0200
Re: Learning Modules, Arguments, Parameters (imma noob) Cody Cox <codywcox@gmail.com> - 2015-09-25 13:52 -0700
Re: Learning Modules, Arguments, Parameters (imma noob) Terry Reedy <tjreedy@udel.edu> - 2015-09-25 20:08 -0400
Re: Learning Modules, Arguments, Parameters (imma noob) Cody Cox <codywcox@gmail.com> - 2015-09-25 11:53 -0700
Re: Learning Modules, Arguments, Parameters (imma noob) Cody Cox <codywcox@gmail.com> - 2015-09-25 12:03 -0700
Re: Learning Modules, Arguments, Parameters (imma noob) Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-25 13:20 -0600
Re: Learning Modules, Arguments, Parameters (imma noob) Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-25 23:59 +0000
Re: Learning Modules, Arguments, Parameters (imma noob) wxjmfauth@gmail.com - 2015-09-26 00:02 -0700
Re: Learning Modules, Arguments, Parameters (imma noob) Larry Hudson <orgnut@yahoo.com> - 2015-09-25 22:55 -0700
csiph-web