repeat program

eschneider92 at comcast.net eschneider92 at comcast.net
Mon Apr 29 20:22:28 EDT 2013


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.



More information about the Python-list mailing list