Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.039 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'else:': 0.03; 'def': 0.12; 'random': 0.14; 'email addr:comcast.net': 0.16; 'received:74.208.4.195': 0.16; 'subject:program': 0.16; 'wrote:': 0.18; 'advance.': 0.19; 'skip:f 30': 0.19; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'player': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'skip:c 30': 0.32; 'proceed': 0.33; 'thanks': 0.36; 'turn': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'more': 0.64; 'spot': 0.65; 'received:74.208': 0.68; 'repeat': 0.74; 'again?': 0.84 Date: Mon, 29 Apr 2013 20:38:41 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: repeat program References: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> In-Reply-To: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:E20dz18xaCNv8W78RR53Lw3oDdIvTlNjaaz6p8IeSIs y5mN0QOWw5taH2RU5lC0gpi8DtRAAn1Bxc24V0Uy9XFahsRJVv BaaRSWbV2HIZP6p6tJH1kxB/6DZCLb/aTELYmqdS1J76nWNFhD zLQBvA4ni6NMemWBKrCD+sjdEvjVQ2FbppItxXVI0AuppO8sw4 wFGSSdtYoyb6PnpgpUetySbtWGnXoSep7l64+WggmKGQ0OXaQL cXC1MG2jzfQ0MP3XCx+Vx+M1/lU9JBHrgMNoFxPh1LlEE9745K 7eaFZkpVEJGUw94K+bRBzLY9yusOuOek4Dzb50E06C2MIaq1Q= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367282351 news.xs4all.nl 15929 [2001:888:2000:d::a6]:32996 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44528 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