[Tutor] User input

URBAN LANDREMAN ulandreman at msn.com
Mon May 22 16:43:47 CEST 2006


You had a typo with the variable 'gallon_price' and your formula for the 
total cost was incorrect.  Adding float() for the raw_input helps.

This code gets you closer:

mpg = float(raw_input ("Enter your mileage:"))
distance = float(raw_input ("Enter your distance:"))
gallon_price = float(raw_input ("Enter you cost per gallon:"))
make = "Honda"
model = "Accord"

##
print make, model, "mileage is", mpg, "miles per gallon"
print "Total trip cost is US$" , distance * gallon_price/mpg

Others who are more experienced may have suggestions for more elegant code.

Urban Landreman




>From: "MATATA EMMANUEL" <emmatata at hotmail.com>
>To: Tutor at python.org
>Subject: [Tutor] User input
>Date: Mon, 22 May 2006 09:58:04 -0400
>MIME-Version: 1.0
>X-Originating-IP: [199.90.217.113]
>X-Originating-Email: [emmatata at hotmail.com]
>X-Sender: emmatata at hotmail.com
>Received: from bay0-mc9-f10.bay0.hotmail.com ([65.54.245.18]) by 
>bay0-imc2-s36.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 
>22 May 2006 07:01:58 -0700
>Received: from smtp-vbr15.xs4all.nl ([194.109.24.35]) by 
>bay0-mc9-f10.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 
>22 May 2006 07:01:48 -0700
>Received: from bag.python.org (bag.python.org [194.109.207.14])by 
>smtp-vbr15.xs4all.nl (8.13.6/8.13.6) with ESMTP id k4MDwC09055356;Mon, 22 
>May 2006 15:58:12 +0200 (CEST)(envelope-from tutor-bounces at python.org)
>Received: from bag.python.org (bag [127.0.0.1])by bag.python.org (Postfix) 
>with ESMTP id 803111E4016;Mon, 22 May 2006 15:58:11 +0200 (CEST)
>Received: from bag.python.org (bag [127.0.0.1])by bag.python.org (Postfix) 
>with ESMTP id A42201E4007for <Tutor at python.org>; Mon, 22 May 2006 15:58:09 
>+0200 (CEST)
>Received: from bag (HELO bag.python.org) (127.0.0.1)by bag.python.org with 
>SMTP; 22 May 2006 15:58:09 +0200
>Received: from hotmail.com (bay107-f11.bay107.hotmail.com [64.4.51.21])by 
>bag.python.org (Postfix) with ESMTPfor <Tutor at python.org>; Mon, 22 May 2006 
>15:58:08 +0200 (CEST)
>Received: from mail pickup service by hotmail.com with Microsoft 
>SMTPSVC;Mon, 22 May 2006 06:58:07 -0700
>Received: from 64.4.51.220 by by107fd.bay107.hotmail.msn.com with HTTP;Mon, 
>22 May 2006 13:58:04 GMT
>X-Message-Info: LsUYwwHHNt1YS4l5TKo3dHnFdM1dcnJLvFKeEzvkf14=
>X-Original-To: Tutor at python.org
>Delivered-To: tutor at bag.python.org
>X-Spam-Status: OK 0.075
>X-OriginalArrivalTime: 22 May 2006 13:58:07.0284 
>(UTC)FILETIME=[C0B69740:01C67DA7]
>X-BeenThere: tutor at python.org
>X-Mailman-Version: 2.1.7
>Precedence: list
>List-Id: Discussion for learning programming with Python <tutor.python.org>
>List-Unsubscribe: 
><http://mail.python.org/mailman/listinfo/tutor>,<mailto:tutor-request at python.org?subject=unsubscribe>
>List-Archive: <http://mail.python.org/pipermail/tutor>
>List-Post: <mailto:tutor at python.org>
>List-Help: <mailto:tutor-request at python.org?subject=help>
>List-Subscribe: 
><http://mail.python.org/mailman/listinfo/tutor>,<mailto:tutor-request at python.org?subject=subscribe>
>Errors-To: tutor-bounces at python.org
>X-Virus-Scanned: by XS4ALL Virus Scanner
>Return-Path: tutor-bounces at python.org
>
>
>
>Hi there,
>
>Can anyone tell me how I'm having trouble executing this piece of code:
>
>mpg = raw_input (" Enter your mileage:")
>distance = raw_input ("Enter your distance:")
>galon_price = raw_input ("Enter you cost per gallon:")
>make = "Honda"
>model = "Accord"
>##
>print make, model, "mileage is", mpg, "miles per gallon"
>print "Total trip cost is US$", distance / (mpg * gallon_price)
>
>
>I get this error when I run it:
>
>print "Total trip cost is US$", distance / (mpg * gallon_price)
>TypeError: unsupported operand type(s) for *
>
>
>
>Matt
>


>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list