[Tutor] Repeat Until Dead

Alan Gauld alan.gauld at btinternet.com
Thu Jun 27 01:23:52 CEST 2013


On 26/06/13 23:07, Danilo Chilene wrote:
> Hello,
>
> Try something like this:
>
> coin = raw_input('Insert coins:\n')
>
> while(coin > 0):
>      coin = int(coin)-1
>      print 'You have {0} coin(s)'.format(coin)

Note you did not convert the original raw_input value to an int.
Also you keep on converting coins to int inside the loop even
though it already is one after the first iteration. However...

This only loops for as many times as coin is set at the beginning.
The OP needs the raw_input inside the loop so it would need to look
like this:

coin = int( raw_input('Insert coins:\n') )
while(coin > 0):
      print 'You have {0} coin(s)'.format(coin)
      coin = int( raw_input('Insert coins:\n') )

What we don't know, because the OP didn't tell us, is how
he detects "death"... I hope he can adapt...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list