0% found this document useful (0 votes)
7 views

Adventure Story Program in Python - A Step-by-Step Guide

Uploaded by

kt486751
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Adventure Story Program in Python - A Step-by-Step Guide

Uploaded by

kt486751
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Adventure Story Program in Python: A Step-by-Step Guide

Objective:
You will create an adventure story program using Python. This program will include various elements such
as comments, strings, print statements, user input, conditional statements (if, elif, else), random choices,
booleans, and library imports.

Steps to Complete Your Assignment:


Step 1: Set Up Your Python Environment
1. Open your Python development environment (like IDLE, PyCharm, or Jupyter Notebook).

2. Create a new Python file and name it adventure_story.py.

Step 2: Add Header Comments


● Write a header comment at the top of your program to describe what your program does.

● Example format:

# Adventure Story Program # Author: Your Name # Date: Today's Date # Description: A simple
adventure story that allows the user to make choices.

Step 3: Import Libraries


● Import any libraries you might need. For example, you will need the random library for random
choices.

import random

Step 4: Write Strings for Your Story


● Create strings that will be used in your story. Think of different parts of your adventure.

● Example:

intro = "Welcome to the Adventure! You are in a dark forest." choice1 = "Do you want to go left or
right?"

Step 5: Use Print Statements


● Use print statements to display the strings you created.

● Example:

print(intro) print(choice1)
Step 6: Get User Input
● Use the input() function to ask the user for their choices.

● Example:

direction = input("Enter 'left' or 'right': ")

Step 7: Implement Conditional Statements


● Use if, elif, and else statements to create different paths in your story based on user input.

● Example:

if direction == "left": print("You encounter a friendly dragon.") elif direction == "right":


print("You find a treasure chest!") else: print("That's not a valid choice.")

Step 8: Add Random Choices


● Use the random.choice() method to add an element of surprise in your story.

● Example:

outcomes = ["You win a prize!", "You fall into a trap!", "You find a magic potion!"]
print(random.choice(outcomes))

Step 9: Use Boolean Variables


● Create a boolean variable to track a condition in your story.

● Example:

has_key = True # This means the user has a key to open a door.

Step 10: Add Comments Throughout Your Code


● Include at least 10 single-line comments to explain different parts of your code.

● Example:

# This is the introduction to the adventure

Step 11: Test Your Program


● Run your program to ensure it works as intended.

● Make adjustments as necessary to improve the flow of the story.

Step 12: Submit Your Program


● Save your work and submit your adventure_story.py file as required by your teacher.
Vocabulary to Know:
● Header Comment: A note at the top of your program that explains what it does.

● String: A sequence of characters used to represent text.

● Print Statement: A command that outputs text to the screen.

● Input: A function that allows the user to enter data.

● Conditional Statements: A way to execute different code based on certain conditions (if, elif, else).

● Random Choice: A selection made at random from a list of options.

● Boolean: A variable that can be either True or False.

● Import Libraries: Bringing in external code libraries to use their functions.

Good luck with your adventure story program! Remember to take it one step at a time.

You might also like