Guess It in python
# Guess what number for python. My one of first python codes so it prolly looks ugly as hell.
# E.K.virtanen. 2007, public domain

# modules we need here
import random
import os

# function wich solves what OS is used. linux and windows regignized.
def os_clear():
    return_value = "\n"
    if os.name == "posix":
        return_value = 'clear'
    elif os.name in ("nt", "dos", "ce"):
        return_value = 'CLS'
    return return_value

# Constant variables
const_min = 1
const_max = 100

clear_screen = os_clear()

# MAIN MODULE OF PROGRAM
guess_game = end_game = 'play'
while end_game == 'play':
    os.system(clear_screen)

    randomed = random.randint(const_min, const_max)
    rounds = 0
    print 
    print 'Ok, i think random number between ', str(const_min), ' to ' + str(const_max)
    print 'Your job is to guess what it is in as minimal tries as possible.'
    print ''
    print 'After your every guess, ill give you hint is my number higher or lower than your guess.'
    print 'You can exit by "guessing" (0).'
    raw_input('Press <ENTER> to start game.')

        # guessing part of game
    os.system(clear_screen)
    while guess_game == 'play':
        rounds += 1
        print 'This is rounds number: ', str(rounds) + '.'
        print
        plr_guess = int(raw_input('Give your guess: '))
        if int(plr_guess) < randomed:
            print 'My number is higher...'
        elif int(plr_guess) > randomed:
            print 'Mu number is lower...'
        elif int(plr_guess) == randomed:
            guess_game = 'stop'
        elif int(plr_guess) == 0:
            break
        else:
            print 'Give value between ', str(const_min), ' to ' + str(const_max), ' please.'

    if guess_game == 'stop':
        end_game = 'stop'
        os.system(clear_screen)
        print 'You got it!'
        print 'It took ', str(rounds), ' rounds to guess right number.'
        print 
        print ' Press <y> + <ENTER> to play again. <ENTER> only to quit.'
        if raw_input() == 'y':
            guess_game = end_game = 'play'
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.