Python Coding

1,353

12

3

Posted in TechnologyComputers

Introduction: Python Coding

About: I have seen the world grow. And also lasers

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!

Share

    Recommendations

    • Spotless Contest

      Spotless Contest
    • Microcontroller Contest

      Microcontroller Contest
    • Space Challenge

      Space Challenge
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    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!