Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97087

Re: Learning Modules, Arguments, Parameters (imma noob)

From John Gordon <gordon@panix.com>
Newsgroups comp.lang.python
Subject Re: Learning Modules, Arguments, Parameters (imma noob)
Date 2015-09-24 19:32 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <mu1j3u$mm2$1@reader1.panix.com> (permalink)
References <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com>

Show all headers | View raw


In <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> codywcox@gmail.com writes:

> 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?

>  def get_input(kilo):
>    kilo = float(input('Enter Kilometers: '))
>    return kilo

get_input() gets all its input from the keyboard.  It doesn't need any
arguments.

>  def convert_kilo(kilo,miles):
>      miles = float(kilo * 0.6214)
>      print( kilo,' kilometers converts to ',miles,' miles')

convert_kilo() calculates miles on its own, so you don't need to pass it
as an argument.

> def main():
>    get_input()
>    convert_kilo()
>
>  main()

When calling get_input, you need to save the return value in a variable,
and then pass that variable as an argument to convert_kilo.

The updated code would look like this:

def main():
    kilo = get_input()
    convert_kilo(kilo)

def get_input():
    kilo = float(input('Enter Kilometers: '))
    return kilo

def convert_kilo(kilo):
    miles = float(kilo * 0.6214)
    print( kilo,' kilometers converts to ',miles,' miles')

main()

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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