This python script is a little guessing game, where you guess a number from 1 – 100
Script white space is broken due to wordpress being… Silly… I will fix it soon.
#!/usr/bin/env python # Import the random module import random # Create a random number between 1 and 100 secret = random.randrange(1,100) # Count the score(lower the better) count = 0 print "Guess a number from 1 to 100" # This will loop as long as secret is equal to anything while secret: # Increment score count += 1 # Try to something, if there is an error raise exception try: # Get input from user and check if it is a number between 1 and 100. If you guess correct it will let you know and end the loop guess = int(raw_input("Enter a guess: ")) if guess < 100 and guess > 1: if guess < secret: print "Too low!" elif guess > secret: print "Too high!" else: print "Correct! Guesses taken: " + str(count) secret = None else: raise Exception() except: print "Error: invalid data - Please input a integer between 1 and 100"