programming

Xavier Ho contact at xavierho.com
Mon Sep 20 03:29:30 EDT 2010


Okay, it looks like you're doing well. I'm just going through your second
email now, and it seems many of my comments in the first email is irrelavent
to you anymore, because you already knew how to do it. =]

Let's have a look. Again, my reply is in Blue.

.

*And what I've attempted to do so far....

*so far, i have gone into the cs150 directory as instructed and created a
project0 directory. in that directory i typed in touch support.py and touch
stopping.py to create the support and stopping files. is that correct so
far?

then i typed in vim support.py to edit the support.py file.

I believe in vim you can save your file, too, anyway, so the touch part is
probably unnecessary, but won't hurt.

def distance(a,b,c,d):
    return sqrt(a**2+b**2), sqrt(c**2+d**2)

That won't do. You're returning the distance between the origin and (a, b),
and another distance between the origin and (c, d).

Think about this again. If I understand this correctly, you should be only
returning one value (not two, which is what you're doing now), that is the
distance between (a, b) and (c, d).

from support import*

from support import *
Note the space before *. It makes things more pleasant, even when your
version compiles.

def main():

    def getinfo():
        amplitude=eval(input("
Amplitude of the sine wave (in feet): "))
        period=eval(input("Period of the sine wave (in feet): "))
        xDistance=eval(input("Distance to the stop sign (in feet): "))
        distance2=eval(input("Distance needed to stop without using brakes
(in feet): "))
        return amplitude,period,xDistance,distance2

    amplitude,period,xDistance,distance2=getinfo()
    s=sineLength(amplitude,period,xDistance,1)
    print(xDistance,distance2,s)

I'm almost 100% certain your instructor wanted you to have getinfo() outside
of main(). It's valid to have a function inside a function, but there's not
much point to it.

Secondly, that doesn't even compile. Nor does

xDistance=eval(input("Distance to the stop sign (in feet): "))

by itself. Without going into how slobby the use of eval() is in your case,
you can fix it and make it syntax-legal by adding another quotes around your
input function.

xDistance = eval('input("Distance to the stop sign (in feet): ")')

main()

It's okay to run your main() method that way, as long as you're sure
stopping.py isn't going to be imported by anyone else.

I realize this is probably elementary, but I've never done anything like
this, and kind of got thrown into it. It's very much a
teach-yourself-course, so I guess if you don't really understand the lingo,
it's easy to fall behind.

You're doing well as far as I can tell.

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100920/8d5c1322/attachment.html>


More information about the Python-list mailing list