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
MATATA EMMANUEL wrote:
> 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"
raw_input reads in the value as a string, so you need
to convert it at some point to a number. You can
either do this at the point where you read the value
in, or when you do the calculation/print.
To convert it at the input stage (probably the most
logical), add float() such as
mpg = float(raw_i
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_inpu
Thanks Kelly.
The second version works.
print "Total trip cost is US$", float(distance) /(float(mpg) * float(galon_price))Matt
From: Kelly Vincent <[EMAIL PROTECTED]>To: MATATA EMMANUEL <[EMAIL PROTECTED]>, Tutor@python.orgSubject: Re: [Tutor] User inputDate: Mon, 22 May 2006 15:19:12 +
> The second version works.
>
> print "Total trip cost is US$", float(distance) /
> (float(mpg) * float(galon_price))
Hi Matt,
Although this works, we'll probably want to do the type conversions as
early as possible. We can write a function input_float() that wraps up
the float(raw_input()) s
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi Everyone,
I am getting an odd traceback when using a class.
The class I am using is
class TriggerMessage:
def __init__(self,data):
"""
Unpacks the passed binary data based on the MQTCM2
On Mon, 22 May 2006, Andrew Robert wrote:
> class TriggerMessage:
>
> def __init__(self,data):
This suggests that it's to be invoked along the lines of:
foo = TriggerMessage(data)
> def decode(self):
And this as:
bar = foo.decode()
> test = TriggerMessage.decode(data)
I need help on this script. I'm trying to download zip file from the web and store it to my local drive: It is printing info, but doesn't download any thing. Can anyone assist here?
import urllibimport sys# Get a file-like object from the web and store it locally.url = ""http://www.esri.com">"f =
Hello, I am pretty sure I am sending this to the right email address. But anyway I need help. I started learning python, and I wanna know how to make a simple program, that displays text and when the user presses enter more text is displayed. And so and so until the end. Thank you, joe.
Love
On Mon, 22 May 2006, MATATA EMMANUEL wrote:
> import urllib
> import sys
> # Get a file-like object from the web and store it locally.
> url = "http://www.co.rowan.nc.us/enviroservs/downloads.htm";
> f = urllib.urlopen(url)
> # connect to the remote
> try:
> remote = urllib.urlopen(url)
> ex
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi Everyone,
When I try to use the class listed below, I get the statement that self
is not defined.
test=TriggerMessage(data)
var = test.decode(self.qname)
I would have thought that self would have carried forward when I grabbed
an
Terry Carroll wrote:
> I apologize for this off-topic question -- the only real connection to
> Python is that I'm using Python as my programming language.
>
> I'm writing a program to analyze an MP3 file's contents. I need to
> find a newsgroup or other forum to ask some questions about file
Danny,
I just made some changes, but I still can't get my file saved on my local drive:
here is the new version of the code:
++
import urllibimport sys
# Get a file-like object from the web and store it locally.
url = ""http://www.co.rowan.nc
On Mon, 2006-05-22 at 14:28 -0400, Andrew Robert wrote:
> When I try to use the class listed below, I get the statement that
> self
> is not defined.
>
> test=TriggerMessage(data)
> var = test.decode(self.qname)
Perhaps
var = test.decode()
would do
Hi Joe,
> Hello, I am pretty sure I am sending this to the right email
> address.
Looks like it :-)
> But anyway I need help. I started learning python,
How are you learning? Have you found a tutorial yet?
If you already know how to program in another language
the official tutorial on the pyt
> I need help on this script. I'm trying to download zip file from the
> web and store it to my local drive: It is printing info, but doesn't
> download any thing.
Looks like you are a wee bit confused on what you are trying to do.
> import urllib
> import sys
> # Get a file-like object from th
(usually best to click reply-All so that the reply goes to the list)
On Mon, 2006-05-22 at 15:08 -0400, Andrew Robert wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Well.. inside the class is the decode function.
The decode method depends on "data" which is referenced as a global.
On Mon, 22 May 2006, MATATA EMMANUEL wrote:
> I just made some changes, but I still can't get my file saved on my local
> drive:
Ok. Up to what part of the program works?
Don't just say it doesn't work: can you try isolating what parts are
working as expected, and what parts aren't working a
Alan,
I have changed the code as following but it still printing the contains as something I don't know what it is instead of saving locally! If you click the link in this code, you will see the type of file I would like to be able to download in this script.
import urllibimport sys
# Get a file-
Danny,
This script has to do two things:
1) Hit a site where I would like to download something
2) Read it what the file
3) Download it locally.
I'm a beginner, but according to what it is printing I'm thinking it is opening and is able to read the site (I'm wrong since I have been studying Pytho
> I have changed the code as following but it still printing the
> contains as something I don't know what it is instead of saving
> locally!
You need to step back a bit and get a better understanding of
variables
and functions and how to use them. You are trying to run before you
can walk.
>
> Hey Alan, I have indeed found a tutorial. "A Byte Of Python"
Yes, that should be fine for you.
> So far it's really good. I'm down around functions, and is this far
> enough?
I'm not sure which order it covers things but somewhere soon
you should find the stuff about reading text from files
> When I try to use the class listed below, I get the statement that
> self
> is not defined.
>
> test=TriggerMessage(data)
> var = test.decode(self.qname)
>
> I would have thought that self would have carried forward when I
> grabbed
> an instance of TriggerMessage.
self is a special varianble
Hi,
How can I set tab as default indendation for the file editor window in
IDLE? I tried to change this in "Configuration Window" and "Apply", but
still get 4 spaces. What does work is setting indentation to "8" and
then enabling toggle tabs when I open a new window.
Thanks,
Cecilia
___
Hello, I just got Python In a Nutshell and decided to play around with the time section. While playing with the calendar module, I encountered a problem:>>> import calendar>>> calendar.calendar
(2006)' 2006\n\n January February
On 23/05/06, Shuai Jiang <[EMAIL PROTECTED]> wrote:
> Hello,
> I just got Python In a Nutshell and decided to play around with the time
> section. While playing with the calendar module, I encountered a problem:
>
> >>> import calendar
> >>> calendar.calendar (2006)
> '
Hello list,
I want to use the module StringIO as read and write strings as files, I
looked into document but cannot understand.
Could anyone give me a simple example?
something like:
from StringIO import *
fin = StringIO("abc")
.
How can I used fin?
Thanks,
da
__
I am looking for Matthew White. How can I reach him.
Jen
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
> I want to use the module StringIO as read and write strings as files, I
> looked into document but cannot understand. Could anyone give me a
> simple example?
>
> something like:
> from StringIO import *
> fin = StringIO("abc")
> .
> How can I used fin?
'fin' is a file-like object at this
On Mon, 22 May 2006, [EMAIL PROTECTED] wrote:
> I am looking for Matthew White. How can I reach him.
Hi Jennifer,
We probably can not help you much with this. It would help very much if
you could somehow explain why you posted this question here on Tutor. It
is not obvious how this is rel
use print!
print calendart.calendar(2006)
Alan G.
- Original Message -
From: "Shuai Jiang" <[EMAIL PROTECTED]>
To:
Sent: Tuesday, May 23, 2006 2:09 AM
Subject: [Tutor] Calendar Module
Hello,
I just got Python In a Nutshell and decided to play around with the
time
section. While play
Danny Yoo wrote:
>> I want to use the module StringIO as read and write strings as files,
>> I looked into document but cannot understand. Could anyone give me a
>> simple example?
>>
>> something like:
>> from StringIO import *
>> fin = StringIO("abc")
>> .
>> How can I used fin?
>
> 'fin' is
33 matches
Mail list logo