Path: csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'value,': 0.03; 'float': 0.05; 'converts': 0.07; 'variable,': 0.07; "'''": 0.09; 'caller.': 0.09; 'complaining': 0.09; 'parameter.': 0.09; 'prevents': 0.09; 'subject:Modules': 0.09; 'python': 0.10; 'def': 0.13; 'argument': 0.15; "'))": 0.16; '0.0,': 0.16; 'guessing': 0.16; 'main():': 0.16; 'subject:Learning': 0.16; 'variable.': 0.16; 'wrote:': 0.16; 'memory': 0.17; "shouldn't": 0.18; 'creates': 0.18; 'skip:= 10': 0.18; 'variable': 0.18; '2015': 0.20; 'suggested': 0.20; 'arguments': 0.22; 'either.': 0.22; 'noted': 0.22; 'sep': 0.22; 'pass': 0.22; 'passing': 0.23; 'replacing': 0.23; 'header:In- Reply-To:1': 0.24; 'all.': 0.24; "doesn't": 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'actual': 0.28; 'fine': 0.28; 'initialized': 0.29; 'convert': 0.29; 'print': 0.30; 'work.': 0.30; 'probably': 0.31; 'another': 0.32; 'returned': 0.32; 'received:google.com': 0.35; 'next': 0.35; 'could': 0.35; "isn't": 0.35; 'problem.': 0.35; 'but': 0.36; 'should': 0.36; 'needed': 0.36; 'there': 0.36; '(and': 0.36; 'assigned': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'no,': 0.38; 'anything': 0.38; 'skip:p 20': 0.38; 'why': 0.39; 'data': 0.39; 'sure': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'advanced': 0.61; 'above,': 0.63; 'more': 0.63; 'here': 0.66; 'below.': 0.66; 'saving': 0.70; 'about,': 0.84; 'miles.': 0.84; 'to:name:python': 0.84; 'poorly': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=lTY4VWEfIR9bT6ibkCBE+nhlOQH+lG6MyyQxlZ6aAl8=; b=v4QXJllvwedIqhGcru+0zEKhR0pp220wNIqEVxinuaJlykR8YVEQ/t5QWFnfA+jHv1 APTO+nR6iJrqwp0o3B+Go4SzvO0asn+qnCD4Kml90B16yu9egznqMiNysU5Slwvtl6G5 WnJmdUwSfjkRCHZUjY1WjM0EnIprcX+DitGrJbm55j9GX3ulgHb89uCCBYXtu62Ay/us Y77kdVUkyo8WBsAbgNkhpQua7hQywN7IQGMSpQXSTVQcw0BmUY9e/Ao5Oylf1eyNUQvi Nms54YTyhzBnp5iuEjr+mEXtt+jDyYO3RlObSewh+Xd6hBnbsEpdN2fI5r7prg8u20Od FeJw== X-Received: by 10.170.48.210 with SMTP id 201mr6421660ykq.32.1443208887245; Fri, 25 Sep 2015 12:21:27 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> From: Ian Kelly Date: Fri, 25 Sep 2015 13:20:47 -0600 Subject: Re: Learning Modules, Arguments, Parameters (imma noob) To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443208890 news.xs4all.nl 23740 [2001:888:2000:d::a6]:46533 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97126 On Fri, Sep 25, 2015 at 1:03 PM, Cody Cox wrote: > def main(): > #set the variable to 0.0, makes it a float and creates a place in memory for the variable. > kilo = 0.0 This is addressing a symptom, not the actual problem. Initializing kilo here prevents Python from complaining when you try to access the kilo variable in the "kilo = get_input(kilo)" line below. However, you don't need it there either. > ''' > this I am not sure about, I set Kilo=get_input(kilo), but why do I need the argument when > I am going to pass it to convert_to_kilometers? but the program works so I am guessing that is where it is saving > the variable in order to be passed? so it needs to be returned as an argument to be passed as an argument for > the next call??? > > ''' > kilo = get_input(kilo) No, you don't need the argument at all. You use arguments to pass in data that the function needs to do its work. In this case you're passing in the *current* value of kilo, which you set above to be 0.0. This isn't data that is needed by get_input, so you shouldn't pass it in (and the get_input function should not require it). The result of the get_input call is then assigned to kilo, replacing the 0.0 which you don't need. It's fine for kilo to be initialized with this line rather than the one above. > convert_to_kilometers(kilo) This is okay, but as you get more advanced you will probably want this function to return a value, which you could store in another variable, e.g.: miles = convert_to_miles(kilo) > def get_input(kilo): > kilo =float(input('Enter the amount of Kilometers: ')) > return kilo As noted above, this function should not have kilo as a parameter. It never uses it. This function needs to return kilo *to* its caller, not take a value for kilo *from* its caller. > def convert_to_kilometers(kilo): > miles = kilo * .6214 > print(kilo,'Kilometers converts to: ',miles, ' Miles.') This is fine but poorly named. This function converts kilometers to miles. It doesn't convert anything to kilometers as suggested by the name. And again, as you get more advanced you would probably want this to return the value of miles rather than just print it.