Day 13: Exploring Python – Creating Games

We start Day 13 with a new resource – a book available for reading online – Invent Your Own Computer Games with Python (4th Edition) by Al Sweigart.

1. Introduction – after installation – Start IDLE (Interactive DeveLopment Environment), on Windows, click the Start menu in the lower-left corner of the screen, type IDLE, and select IDLE (Python GUI).

2. Chapter 2: Hello World

print(‘Hello world!’)
print(‘What is your name?’)
myName = input()
print(‘It is good to meet you, ‘ + myName)

3. Chapter 3: Guess The Number – Some part of the code:

  • import random
  • number = random.randint(1, 20)
  • for i in range(6) – range() function that specifies the number of loops. Value of variable i get set from 0 to 5.

4. Chapter 5: How to Play Dragon Realm– Some part of the code:

import random
import time


def displayIntro():
print(”’You are in a land full of dragons. In front of you,
you see two caves. In one cave, the dragon is friendly
and will share his treasure with you. The other dragon
is greedy and hungry, and will eat you on sight.”’)


def chooseCave():
cave = ”
while cave != ‘1’ and cave != ‘2’:
print(‘Which cave will you go into? (1 or 2)’)
cave = input()

return cave


def checkCave(chosenCave):

friendlyCave = random.randint(1, 2)

if chosenCave == str(friendlyCave):
print(‘Gives you his treasure!’)
print(‘Gobbles you down in one bite!’)


while playAgain == ‘yes’ or playAgain == ‘y’:
caveNumber = chooseCave()

print(‘Do you want to play again? (yes or no)’)
playAgain = input()

End of Day 13.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s