GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pythoncourse/04-basic-text-based-game.py at master · MoserMichael/pythoncourse

Expand file tree

/

04-basic-text-based-game.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
52 lines (43 loc) · 1.81 KB
/

04-basic-text-based-game.py

Copy path

File metadata and controls

52 lines (43 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# lets make a text based game. it will loop on and on, and display some screens.
# in each screen you will have a set of choices, choosing one will get you to the next screen.
print("You enter a big forrest, now the wolf is coming. What will you do?")
print("1 - run away")
print("2 - talk to the wolf")
print("3 - fight")
choice = input("enter your choice: ")
if choice == "1":
print("you run towards a house, What will you do?")
print("1 - enter the house" )
print("2 - run away")
choice = input("enter your choice: ")
if choice == "1":
print("the witch eats you. game over")
elif choice == "2":
print("you stumble and fall. game over")
else:
print("error, no such choice")
elif choice == "2":
print("the wolf turns out to be nice, he asks you for a present")
print("1 - give him a snack")
print("2 - give him a saussage")
choice = input("enter your choice: ")
if choice == "1":
print("the wolf says 'thank you' and gives you the key to the treasure")
elif choice == "2":
print("the wolf says he is a vegetarian and goes away")
else:
print("error, no such choice")
elif choice == "3":
print("you win the fight, but you gained nothing...")
else:
print("error, no such choice")
print("*** game over ***")
# exercise: make your own adventure game like this.
# Extend it to behave differently, based on some choices you did in a previous screen.
# Extend it to get different score, based on the decissions you are making
# extend the game so that you have different outcomes based on random number being drawn.
# you can get random numbers as follows.
import random
# the next statement will assign a random number between 1 and ten to the variable choice.
random_choice = random.randint(1,10)
print("random choice: ", random_choice)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.