Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44529
| Date | 2013-04-30 01:43 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: repeat program |
| References | <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1169.1367282589.3114.python-list@python.org> (permalink) |
On 30/04/2013 01:22, eschneider92@comcast.net wrote:
> How do I make the following program repeat twice instead of asking whether the player wants to play again?
>
>
> import random
> import time
>
> def intro():
> print('You spot 2 caves in the distance.')
> print ('You near 2 cave entrances..')
> time.sleep(1)
> print('You proceed even nearer...')
> time.sleep(1)
>
> def choosecave():
> cave=''
> while cave!='1' and cave !='2':
> print('which cave?(1 or 2)')
> cave=input()
> return cave
>
> def checkcave(chosencave):
> friendlycave=random.randint(1,2)
> if chosencave==str(friendlycave):
> print ('you win')
> else:
> print('you lose')
>
> playagain='yes'
> while playagain=='yes':
> intro()
> cavenumber=choosecave()
> checkcave(cavenumber)
> print('wanna play again?(yes no)')
> playagain=input()
>
> Thanks in advance.
>
Replace the 'while' loop with a 'for' loop that loops twice.
By the way, there's a bug in 'choosecave': what happens if the user
enters, say, '3'?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
repeat program eschneider92@comcast.net - 2013-04-29 17:22 -0700 Re: repeat program Denis McMahon <denismfmcmahon@gmail.com> - 2013-04-30 00:33 +0000 Re: repeat program Dave Angel <davea@davea.name> - 2013-04-29 20:38 -0400 Re: repeat program MRAB <python@mrabarnett.plus.com> - 2013-04-30 01:43 +0100 Re: repeat program Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-29 19:46 -0600
csiph-web