On 30/04/2013 01:22, eschneide...@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'?

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to