Number guessing game
Platform: Python
Published Jun 09, 2011
Updated Jun 09, 2011
a simple number guessing game
import sys, os, time, random
loop = ["10", "9", "8" ,"7" , "6" , "5", "4", "3" , "2" , "1"]
l = random.choice(loop) # Random choice of loop
if sys.version_info[0] > 2: # fixes python 2 input as raw_input
inp = input # python3 input
else:
inp = raw_input # python2 raw_input
if "-debug" in sys.argv: print("Number is: [\033[31m%s\033[0m]" % l) # For debugging (cough) cheating xD
nc = inp("Guess the number? between 1 and 10 ") # asking for user input
if nc == l: print("yay you got %s" % l) # if user input is equal to random choice of loop print this
time.sleep(1)
os.system("clear")
if not nc == l: print("=/ you no win the number was\n [\033[31m%s\033[0m]" % l) # if user input is not equal to random choice of loop print this
time.sleep(1)
os.system("clear")