Programming Issues

Dave Angel d at davea.name
Thu Sep 20 07:34:34 EDT 2012


On 09/19/2012 07:01 PM, Nathan Spicer wrote:
> Dave,
> 

You sent this response privately, which isn't the way the mailing list
works.  Private responses are good for thank-yous and for personal
remarks of no interest to others.  But you're short-circuiting the
helping process if you don't let everyone else see what you're saying
here.  I'll forward my response to the list, so others can jump in.

You also top-posted, rather than putting your remarks after what you're
quoting.

> I'm running Python 3.2. I think doing raw input is what the instructor is
> looking for.

What version of Python does the instructor think you're using?
raw_input is not in Python 3.2, being renamed to input().  The 2.x logic
of input() is fortunately gone, as it was quite unsafe.

> I know a need to do a loop, but the problem is i don't know ho
> to do this. 

An open-ended loop can be done with the while statement.  What I mean by
open-ended is that you have no way of predicting how many times it will
loop, because it depends on data you don't have ahead of time.  The
other type of loop is the for loop, where the loop will normally
progress till it processes all items in a sequence.

A while loop might look something like:

def ask_user():
    amount = get_amount()
    while amount != 0:
         do_some_stuff(amount)
         amount =  get_amount()
    print "done with program"  #

And your top-level code might look something like:

if __name__ == "__main__":
    ask_user()

If that makes sense to you, then write the functions that this one
calls.  If you don't understand this loop, then ask us to elaborate.
And if you don't understand what this while statement itself does, ask
your professor.


> There is no code, because i'm not sure how or what to write. So
> far we've done simple inputs. Are you aware of any examples similar to my
> problem, that i could look at and possibly base my program accordingly?
> 
> Thanks,
> Nathan
> 


-- 

DaveA



More information about the Python-list mailing list