Python Coding

3.6K123

Intro: Python Coding

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.

STEP 1: Game Setup

Copy in this to the window:

#Ghost Game (not necessary)

from random import randint

print('Ghost Game')

feeling_brave = True

score = 0

STEP 2: Main Loop

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)

STEP 3: Branching Part

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

STEP 4: End Thing

Type:

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

STEP 5: Done!

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

I hope you enjoyed this instructable!

3 Comments

It's much simpler, did you try it? If you do, it will show you how it's different/similar

Is phyton similar to a "basic" basic?... seems to be?

Comment if you have any problems, and I will try and help. Have fun!