[Tutor] infinite loop
alan.gauld at btinternet.com
Fri Nov 18 01:06:44 CET 2011
On 17/11/11 21:29, ADRIAN KELLY wrote:
You don;t need this line because you assign a value to amount
immediately you run main()
> def main():
> amount = float(raw_input('how much do you want to change:'))
> while amount<50:
> print 'Sorry, cannot convert an amount under €50 '
To get a while loop to terminate you must change something about the
In this case the test value 50 is a constant so it needs to be amount
that changes. But you only print a message... You need to read a new amount.
> print 'Your exchange comes to: ',total
You don't really want/need the else: line.
It's not wrong but its more normal to see it done like this:
loop body here
with no explicit else.
In fact, thinking about it, I've never found a use for
the while/else construct, has anyone else?
Author of the Learn to Program web site
More information about the Tutor