[Tutor] My first python program!
Kevin
python_newbie at vedorian.com
Tue Aug 17 23:58:24 CEST 2004
Ok here is something I can't figure out I put a define at the top of the
program called tries = 5
I need to make this part of the program count down from 5 every time they
get a guess wrong. How do I do that?
def game2():
a = randrange(1, 10)
guess = int(raw_input("Pick a number from 1 to 10, You only get 5 tries!:
\r\n") )
while guess != a:
print "Thats not it!\r\n"
guess = int(raw_input("Pick a number from 1 to 10, You only get 5
tries!: \r\n") )
else:
print "Congrats! that was the correct number!\r\n"
ans = raw_input("Would you like to play again?[y/n]: ")
if ans == 'y':
game2()
else:
while ans != 'n':
print "That is not a choice!\r\n"
ans = raw_input("Would you like to play
again?[y/n]: ")
print "Thank you for playing, come back again!\r\n"
Thanks
Kevin
----- Original Message -----
From: "Kevin" <python_newbie at vedorian.com>
To: "Python" <tutor at python.org>
Sent: Tuesday, August 17, 2004 5:44 PM
Subject: Re: [Tutor] My first python program!
> Ya I when I copied and pastet the code I missed the import. As for the
other
> ones I forgot to chage the 100 to 10(It was a pain in the but trying to
see
> if the program worked starting from 1 and making my way to 100 lol.).
Thanks
> for the suggestions I will work on that and try and fix it.
>
> Kevin
> ----- Original Message -----
> From: "Britt Green" <seamonkeys at gmail.com>
> To: "Kevin" <python_newbie at vedorian.com>
> Sent: Tuesday, August 17, 2004 5:34 PM
> Subject: Re: [Tutor] My first python program!
>
>
> > Hi Kevin,
> >
> > Your first program looks pretty good. A lot better than my first
program!
> ;)
> >
> > Anyways, here's some constructive criticism. I tried to run your
> > program but got the error: NameError: global name 'randrange' is not
> > defined. I'm guessing this is because you just forgot to include the
> > import of the random module in the email. ;)
> >
> > In the game2() module, the player is first asked to pick a number from
> > 1-10. But for every guess thereafter, they have to pick between 1-100!
> > Eek! It could just be a typo, though.
> >
> > The serious bug I found in your program is that the game doesn't end
> > after five rounds. It ends only when the player correctly guesses the
> > right number. You should rewrite the while loop so it terminates when
> > the number of guesses variable reaches five. Otherwise, your program
> > is a great one, especially for a first attempt!
> >
> > Britt
> >
> >
> > ----- Original Message -----
> > From: Kevin <python_newbie at vedorian.com>
> > Date: Tue, 17 Aug 2004 15:31:47 -0400
> > Subject: [Tutor] My first python program!
> > To: Python <tutor at python.org>
> >
> >
> > The programm looks a little messed up in email but it looks fine in IDLE
> > But here is the number guessing I just made as my very first programm.
> > Any suggestions on how to improve it would be greate.
> >
> > Kevin
> >
> > def enter():
> > print """
> > ***************************************
> > * *
> > * The Number Guessing Game *
> > * By: Cadon *
> > ***************************************
> > |||||||||||||||||||||||||||||||||||||||
> > + Please enter a choice! +
> > + 1) Enter game +
> > + 2) Exit +
> > +++++++++++++++++++++++++++++++++++++++\r\n"""
> > enter = raw_input("What is your choice? ")
> > if enter == '1':
> > game()
> > else:
> > print '\r\nThank you from looking at the game!'
> >
> >
> > def game():
> > print "welcome to the number guessing game!\r\n"
> > name = raw_input("What is your name? \r\n")
> > print "Thank you %s, lets continue to the game now!\r\n" % name
> > game2()
> > def game2():
> > a = randrange(1, 10)
> > guess = int(raw_input("Pick a number from 1 to 10, You only get 5
> > tries!: \r\n") )
> > while guess != a:
> > print "Thats not it!\r\n"
> > guess = int(raw_input("Pick a number from 1 to 100, You only get
> > 5 tries!: \r\n") )
> > else:
> > print "Congrats! that was the correct number!\r\n"
> > ans = raw_input("Would you like to play again?[y/n]: ")
> > if ans == 'y':
> > game2()
> > else:
> > print "Thank you for playing, come back
> again!\r\n"
> >
> >
> > enter()
> >
> >
> >
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.726 / Virus Database: 481 - Release Date: 7/22/04
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.726 / Virus Database: 481 - Release Date: 7/22/04
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.726 / Virus Database: 481 - Release Date: 7/22/04
More information about the Tutor
mailing list