[Tutor] guess the number game help

Diana Hawksworth dianahawks at optusnet.com.au
Sat Apr 30 10:49:48 CEST 2005

Hello list!

I have started teaching Python to a group of High School students. I set them the "Guess the Number" game as a GUI as an assignment. One of the students has passed in some script that is foreign to any tutorial work we have done.  Some of it is below. Does anyone recognise it? Can you tell me where it would have been downloaded from? I have searched for scripted guess the number games, but there are thousands of them - except for a Python version. 

If my student has plagiarised - I need to know.

TIA Diana

from Tkinter import *

from whrandom import *



class rand: 

   def __init__(self, low, high):   #whrandom number is made here

      self.ro = whrandom()

      self.num = self.ro.randint(low, high)


   def number(self):                

      return self.num


   def set(self):                   

      self.num = self.ro.randint(low, high)


#this part evaluates the users guess

def evaluate_ans(guess_str, whrandom, low_str, high_str, guess_left, \

                 guess_eval_str, yg_label):

   guesses_left = int(guess_left.get())   

   guesses_left = guesses_left - 1


   guess = int(guess_str.get())

   if guess == whrandom.number():           #User has guessed the number.



   else:                                  #User has not guessed the number.

      if guess < whrandom.number():            #Guess is too low.


         guess_eval_str.set("too low")

      elif guess > whrandom.number():          #Guess is too high.


         guess_eval_str.set("too high")


      if guesses_left == 0:                  #User has no guesses left.

         yg_label.configure(text="Correct answer:")





#Reset variables for next game

def reset(whrandom,play_agn, low_str, high_str, guess_left, guess_str, \

          yg_label, guess_eval_str, low, high):



   low_str.set(str(low - 1))

   high_str.set(str(high + 1))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050430/0b0dd14a/attachment.html

More information about the Tutor mailing list