Learn to Program with Python by Irv Kalb

Learn to Program with Python by Irv Kalb

Author:Irv Kalb
Language: eng
Format: epub, pdf
Publisher: Apress, Berkeley, CA


import random

MAX_GUESSES = 5 # maximum number of guesses allowed

MAX_RANGE = 20 # highest possible number

#Show introduction

print 'Welcome to my Guess the Number program.'

print 'Guess my number between 1 and', MAX_RANGE

print 'You will have', MAX_GUESSES, 'guesses.'

def playOneRound():

#Choose random target

target = random.randrange(1, MAX_RANGE + 1)

#Initialize a guess counter

guessCounter = 0

#Loop forever

while True:

#Ask the user to for a guess

userGuess = raw_input('Take a guess: ')

userGuess = int(userGuess)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.