[Tutor] Please critique my guessing game program. (original) (raw)

Matt Smith smith-matt at tiscali.co.uk
Tue Jul 13 20:36:53 CEST 2004


I just started reading about python a couple of days ago and have just written my first program, a guessing game (project suggested b o by the Python Bibliothecha). I intend to extend the program to make it more user friendly but I'd like to get some initial feedback to catch any poor programming or bad habits as soon as possible. Here's the program:

A guessing game program.

By Matt Smith

import random

Function to create a random number between 1 and 100.

def Random100(): return random.randint(1,100)

Game loop.

def Game(guess): guesses = 1 while guess != number: if guess > number: guess = input("Too high, try again. ") else: guess = input("Too low, try again. ") guesses = guesses + 1 print "Well done, you got it in",guesses,"goes."

Main program.

Introduce the program.

print "" print "* Guessing Game *" print "" print

Think of a number.

number = Random100()

Play the game.

print "I am thinking of a number between 1 and 100" guess = input ("What is your first guess? ") Game(guess)

End of program.

Thanks for the help, Matt.



More information about the Tutor mailing list