help with this game

Dag Hansteen d-hanst at online.no
Sun Jul 18 12:43:53 EDT 2004


# You can do it like this:

import random
import sys
from time import sleep

class Mygame:

    def __init__(self):
        self.a = random.randint(1, 100)
        self.c = 0
        self.MAX_TRIES = 10
    

    def startit(self):
        print "Welcome to guess the number"
        print "to play type in a number between 1 and 100."
        print "but you only get ten tries"
        while True:
            while self.c == self.MAX_TRIES:
                print "You have no more tries sorry."
                sleep(5)
                sys.exit()
                
            self.b = input("Guess a number: ")

            if self.b == self.a:
                print "you got it in ",self.c," tries"
                sleep(5)
                sys.exit()
                
            while self.b != self.a:
                self.c = self.c + 1
                if self.b < self.a :
                    print "to low"
                    break
                elif self.b > self.a :
                    print ("to high")
                    break


game = Mygame()
game.startit()





----- Original Message ----- 
From: "Alex Endl" <alexendl at hotmail.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Saturday, July 17, 2004 6:08 PM
Subject: help with this game


> ok now that i know the random function, i made this guessing game.  I get an
> error though, and Im new so im not to good at figuring out what its talking
> about.
> 
> 
> import random
> a = random.randint(1, 100)
> b=-100
> c=0
> print "Welcome to guess the number"
> print "to play type in a number between 1 and 100."
> print "but you only get ten tries"
> while a != b:
>     c = c + 1
>     b = input ("enter guess:")
>     if b < a :
>         print "to low"
>         if c == 10:
>             print "to many guesses"
>         print "trie number", c ("out of 10")
>     elif b > a :
>         print ("to high")
>         if c == 10:
>             print "to many guesses"
>         print "trie number", c ("out of 10")
> print "you got it in ",c," tries"
> 
> 
> thanks for your time
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 




More information about the Python-list mailing list