Python Coding

by MCoder in Circuits > Computers

3830 Views, 12 Favorites, 0 Comments

Python Coding

Screen Shot 2015-06-06 at 3.49.25 PM.png

Today i will show you how to make a simple "ghost game" in python.

I am assuming you have python-if not, click here.

Scroll down and look for "python 3.#.#". The number MUST have a three in front, but the others don't matter.

Then open IDLE (python GUI), open a new file, and save it as ghost game or whatever. All shown above

Note: This is from a book, i am just showing you how to make it on instructables.

Game Setup

Screen Shot 2015-06-06 at 3.57.54 PM.png

Copy in this to the window:

#Ghost Game (not necessary)

from random import randint

print('Ghost Game')

feeling_brave = True

score = 0

Main Loop

Screen Shot 2015-06-06 at 4.06.47 PM.png

This keeps the game going until you guess a "ghost" door

Type in:

while feeling_brave:

ghost_door = randint(1, 3)

print('Three doors ahead...')

print('A ghost behind one...')

print('Which do you open?')

door = input('1, 2, or 3?')

door_num = int(door)

Branching Part

Screen Shot 2015-06-06 at 4.11.35 PM.png

Type in:

if door_num == ghost_door:

print('GHOST!!!!')

feeling_brave = False

else:

print('No ghost!')

print('You enter the next room')

score = score + 1

End Thing

Screen Shot 2015-06-06 at 4.16.26 PM.png

Type:

print('Run away!'
print('You scored', score)

Done!

Save, hit F5 or run in 'run', and play your game.

I hope you enjoyed this instructable!