This is a game written in python in codesculptor. This game is about guessing the number randomly generated by the computer.
It involves guessing the number a given number of times. When a particular range is selected, the number of guesses allowed is fixed appropriately. When the user guesses a number, a message will be displayed whether the guessed number is correct or if the guessed number is higher or lower than the actual generated number. This way, the user makes guesses accordingly, finally converging on the range and getting closer to the actual number.
Here is the Python implementation of Guess the Number game.
This code can be run http://www.codeskulptor.org
# CodeSkulptor runs Python programs in your browser. # Click the upper left button to run this simple demo. # CodeSkulptor runs in Chrome 18+, Firefox 11+, and Safari 6+. # Some features may work in other browsers, but do not expect # full functionality. It does NOT run in Internet Explorer. import simplegui import random message = "Select the Range" count=0 g=0 text=5 high=1000 low=0 number=1000 # Handler for mouse click def function(): global number global message global low global high if number>g: message="Higher. You have "+str(count)+" guesses remaining." low=g elif number=1: print text_input g=int(text_input) count=count-1 function() else: message="You have exhausted your guesses. Try again." # Handler to draw on canvas def draw(canvas): canvas.draw_text(message, [20,112], 18, "Red") # Create a frame and assign callbacks to event handlers frame = simplegui.create_frame("Home", 500, 200) frame.add_button("[0-100)", click) frame.add_button("[0-1000)",click2) frame.set_draw_handler(draw) inp = frame.add_input("Label", input_guess, 100) inp.set_text("New label") # Start the frame animation frame.start()