| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Guessing Game Python - Robbie Haines

Page history last edited by PBworks 15 years, 3 months ago

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.