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


Groups > comp.lang.python > #37743

Re: looking for advice python

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'python': 0.09; 'calculating': 0.09; 'portable': 0.09; 'truncate': 0.09; 'subject:python': 0.11; 'result.': 0.15; '#this': 0.16; 'assignment?': 0.16; 'code?': 0.16; "where's": 0.16; 'string': 0.17; 'wrote:': 0.17; 'specify': 0.17; 'variables': 0.17; 'input': 0.18; 'hey': 0.21; 'not,': 0.21; 'driven': 0.22; 'posted': 0.22; 'programming': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'coding': 0.27; 'separate': 0.27; "doesn't": 0.28; 'post': 0.28; 'decimal': 0.29; 'division': 0.29; 'gather': 0.29; 'convert': 0.29; 'class': 0.29; "i'm": 0.29; 'usually': 0.30; 'int': 0.33; 'much.': 0.33; 'handle': 0.33; 'to:addr:python-list': 0.33; 'version': 0.34; 'program,': 0.34; 'thanks': 0.34; 'pm,': 0.35; 'something': 0.35; 'list.': 0.35; 'but': 0.36; 'useful': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'comment': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'matter': 0.61; 'first': 0.61; 'between': 0.63; 'email addr:gmail.com': 0.63; 'received:74.208': 0.71; 'gas': 0.81; 'received:74.208.4.194': 0.84; 'running,': 0.84; 'subject:looking': 0.91
Date Sat, 26 Jan 2013 18:00:10 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: looking for advice python
References <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com>
In-Reply-To <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:DNeIAo2fLJJu+n9fkBzlhHyJ3i3hb7bGnEaq6QWuJ6F R/OAv1CBggZ76yRAZ/HOftAbWrAjjVrrz1/jTB7Cpl7GYp+oTa RlhTvF9FNi4F37q3CwRtuIaNm/DjsLcUCF7e14f0XZ5OT2laLg iSTzgSx+zL5nr4bUTG01VVCrwggdAfVCbnTVhu+1tcxS6K1JOa oieu2nHRPrcT04mNi3Qklm61sh5DorwPuYjN8T6LhcSNjJe2Zs 15ua7OHlrLbhLCu3ETHkelhfVhL3FUBVfz5gvwtYtePuoO9+CH GjXoHO9TvGrwaXyTEKbhyNb2u0No21igttfVEwjloqY5G3eIA= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1092.1359241236.2939.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359241236 news.xs4all.nl 6984 [2001:888:2000:d::a6]:49710
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37743

Show key headers only | View raw


On 01/26/2013 05:26 PM, twiztidtrees@gmail.com wrote:
> Hey I'm new to programming and I have been working on calculating miles per gallon. iv posted below what I have and constructive criticism would be wonderful. Thanks
>

A good post for the python-tutor mailing list.

If you want help with a program, the first thing you should specify is 
what version of Python you're using.  And usually which OS you're 
running, but in this case it doesn't matter much.


I don't see either a shebang line nor a coding line.


> #This is a program used to calculate miles per gallon
>
>
> #variable used to gather miles driven
> string_miles = input('How many miles did you drive?')
>
> #variable used to gather the amount of gallons used
> string_gas = input('How many gallons of gas did you use?')
>

Why do you bother to have separate variables for the string versions?
Why not just   miles = int( input("xxxx")) ?  For that matter, what if 
the user enters a decimal value for the gallons?  Perhaps you'd better 
use  gas = float( input("yyy") )

> #used to convert the miles input
> miles = int(string_miles)
>
> #used to convert the gas input
> gas = int(string_gas)
>
> #used to calculate mpg through division
> mpg = miles/gas

This isn't portable to Python 2.x.  In 2.x, it would truncate the result.

>
> print(float(string_miles))
> print(float(string_gas))
> print('Your miles per gallon is', format(mpg,'.2f'))
>

What if the user enters something that isn't a valid number, either int 
or float?  Where's the try/catch to handle it?

Is this a class assignment?  If not, why would you have a comment and a 
blank line between every line of useful code?



-- 
DaveA

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


Thread

looking for advice python twiztidtrees@gmail.com - 2013-01-26 14:26 -0800
  Re: looking for advice python Chris Angelico <rosuav@gmail.com> - 2013-01-27 09:48 +1100
  Re: looking for advice python Dave Angel <davea@davea.name> - 2013-01-26 18:00 -0500
    Re: looking for advice python twiztidtrees@gmail.com - 2013-01-27 10:57 -0800
      Re: looking for advice python twiztidtrees@gmail.com - 2013-01-28 13:59 -0800

csiph-web