Year 10 student Robbie Haines' example
# Import Modules
import random
# Introduction Output
print "Lets Play"
print ""
# Define Variables
# Random integer that in the range of 1-100
actualnumber = random.randint(1,100)
guess = 0
guesscount = 0
# As long as the guess isn't the same as
# the real number
while guess != actualnumber:
# Guess Prompt
guess = input("Take A Guess: ")
if guess < actualnumber:
print guess,"Is Too Low!"
elif guess > actualnumber:
print guess,"Is Too High!"
# Adds one guess to the count each time
# an incorrect answer is passed
guesscount = guesscount + 1
# Says 'heat' of guess when in a specific range
# The abs() function converts an integer
# to its absoulte value
if 1 <= abs(actualnumber - guess) <= 20:
print "Guess Is Hot"
print ""
elif 20 < abs(actualnumber - guess) <= 40:
print "Guess Is Warm"
print ""
elif 40 < abs(actualnumber - guess) <= 60:
print "Guess Is Cold"
print ""
elif abs(actualnumber - guess) > 60:
print "Guess Is Freezing"
print ""
# When Guess == Real Number
# End of game..
print ""
print "The Answer Was",actualnumber
print "You Got This Correct In",guesscount,"Attempts"
print ""
print "Good Game Gents.."
print ""
# Exit Prompt
raw_input("Press Enter To Continue..")
----------- OUTPUT -------------------------
Lets Play
Take A Guess: 50
50 Is Too High!
Guess Is Hot
Take A Guess: 49
49 Is Too High!
Guess Is Hot
Take A Guess: 30
30 Is Too Low!
Guess Is Hot
Take A Guess: 40
40 Is Too High!
Guess Is Hot
Take A Guess: 38
38 Is Too Low!
Guess Is Hot
Take A Guess: 39
The Answer Was 39
You Got This Correct In 6 Attempts
Good Game Gents..
Press Enter To Continue..
>>>
Comments (0)
You don't have permission to comment on this page.