I need a lesson.
Bjorn Pettersen
bjorn at roguewave.com
Wed Jun 7 20:36:28 EDT 2000
"F. G. Brown" wrote:
>
> Greetings,
> I just recently started learning to program using Python, and to be honest
> when it comes to programming I'm almost dumb as a rock. I've done some
> Qbasic, but I consider it a dead language as far as the future is concerned
> and wish to concentrate my efforts with Python.
> Here's the rub. The following is a module called howfast.py that I can't
> get to repeat. In Qbasic I would have used a goto at the end and it would
> have worked fine. Of course there is no goto in Python and that where I can
> use anyone's help. See if you can understand what I'm trying to accomplish
> below, it's a little scrambled towards the end, and tell me the error of my
> ways. I have the book "Learning Python" but I'm still stuck. If there are
> any questions I'll be glad to reply.
> Thanks,
> Fred
> ?????????????????????????????????????????????
>
> howfast.py
>
Welcome to Python!
Something like:
d = 'y'
while d == 'y':
a = input("What is the distance you traveled in miles? ")
b = input("How many seconds did it require? ")
c = a*3600.00/b
print "You were going %d mph!" %c
if c > 75:
print "Hey you better slow down!"
d = raw_input ("Would you like to do another? (y)es or (n)o")
if d == 'y':
print 'Here we go!'
else:
print 'See ya!'
will work. Here are some other suggestions (free of charge ;-)
- do yourself a favor and use more than one space to indent
(it's much easier to read with e.g. four space indents).
- name your variables distance, seconds, speed, and answer
instead of a, b, c, and d (when you come back to your
code in a couple of days you'll be glad you did :-)
-- bjorn
More information about the Python-list
mailing list