Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44526 > unrolled thread
| Started by | eschneider92@comcast.net |
|---|---|
| First post | 2013-04-29 17:22 -0700 |
| Last post | 2013-04-29 19:46 -0600 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | eschneider92@comcast.net |
|---|---|
| Date | 2013-04-29 17:22 -0700 |
| Subject | repeat program |
| Message-ID | <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-04-30 00:33 +0000 |
| Message-ID | <kln3h6$f0e$1@dont-email.me> |
| In reply to | #44526 |
On Mon, 29 Apr 2013 17:22:28 -0700, eschneider92 wrote: > How do I make the following program repeat twice instead of asking > whether the player wants to play again? You change something in the folowing two lines: playagain='yes' while playagain=='yes': What you change and how you change it is probably your homework task, so I really shouldn't tell you any more than that. Also, I might not be right about where you need to make the change, but hey, this is the internet, it must be right, yeah? -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-04-29 20:38 -0400 |
| Message-ID | <mailman.1168.1367282351.3114.python-list@python.org> |
| In reply to | #44526 |
On 04/29/2013 08:22 PM, eschneider92@comcast.net wrote:
> How do I make the following program repeat twice instead of asking whether the player wants to play again?
>
Turn it into a function call, and call that function twice from
top-level. Or, more generally,
for i in range(2):
doit()
>
> 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.
>
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-04-30 01:43 +0100 |
| Message-ID | <mailman.1169.1367282589.3114.python-list@python.org> |
| In reply to | #44526 |
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'?
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-04-29 19:46 -0600 |
| Message-ID | <mailman.1170.1367286403.3114.python-list@python.org> |
| In reply to | #44526 |
On Mon, Apr 29, 2013 at 6:43 PM, MRAB <python@mrabarnett.plus.com> wrote: > By the way, there's a bug in 'choosecave': what happens if the user > enters, say, '3'? Then they lose. :-)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web