Assignment 7

Text-Based Adventure with if Statements and for Loops

Objective

In this assignment, you will create a simple text-based adventure game. Your main goals are:

By completing this assignment, you will practice conditional logic, user input handling, and simple iteration with for loops.


Folder Structure

Assignment7/
│
├── islandTreasure.py   # The Python script for the text-based adventure game.
│
└── README.md           # A brief summary of Assignment 7 and its content.

Important: Follow the folder structure exactly as described. This will allow for automated verification of your work.


Overview

Your program will:

What to Do:

Use if statements to create a branching text-based adventure:

Use a for loop in a meaningful way:

Story Outline (suggested scenario):

Gameplay Requirements:

Evaluation Criteria:


Flow Chart

Below is a flow chart that visualizes the possible paths the player might take through the game. Use it as a reference to understand how each decision point leads to different outcomes. You may not need to follow it exactly, but it offers guidance on structuring your logic.

GitLab Sign Up


[Code Hint!]

Below is a partial code snippet (first 34 lines only) of how your forestTreasure.py script might look. If you want you can modify the story and details as long as you meet the requirements:

# Author: Your Name
# Date: MM-DD-YYYY
# Assignment 7

print("Welcome to the Text-Based Adventure Game!")
print("You stand at the edge of a mysterious forest.")

choice1 = input("Type 'go' to enter the forest or 'wait' to stay: ").lower()

if choice1 == "go":
    print("\nYou walk into the forest. The trees grow thicker...")
    choice2 = input("You reach a fork in the path. Type 'left' to go left, 'right' to go right: ").lower()

    if choice2 == "left":
        print("\nYou follow the left path and come to an old hut.")
        print("Inside the hut, you find several items:")

        items = ["apple", "water flask", "torch", "map"]
        for item in items:
            print("-", item)

        choice_item = input("Which item do you take? (apple / water flask / torch / map): ").lower()

        if choice_item == "apple":
            print("\nYou bite the apple, but it gets stuck in your throat. You choke!")
            print("Game Over.")
        elif choice_item == "water flask":
            print("\nYou drink from the flask. It's poisoned! You collapse.")
            print("Game Over.")
        elif choice_item == "torch":
            print("\nYou light the torch and discover a hidden passage.")
            passage_choice = input("Type 'open' to open the passage or 'back' to return to the items: ").lower()

            if passage_choice == "open":

Final Steps

# Assignment7: Text-Based Adventure Game

## Overview

The Assignment7 folder contains:

1. **`forestTreasure.py`**: A Python script that implements a text-based adventure game. 
The game uses `if` statements to create branching storylines and a `for` loop to perform meaningful operations, such as displaying a list of items or numbers. 
Players make choices to navigate through the story, leading to different outcomes based on their decisions.

2. **`README.md`**: This file provides a summary of the contents and objectives of Assignment7.

## Objectives

- Practice using `if/elif/else` statements for decision-making and branching logic.

- Learn how to incorporate `for` loops into a meaningful game scenario.

- Create a program that gracefully handles user input and provides logical responses to player choices.

- Design a simple yet interactive game to engage users while practicing fundamental programming concepts.

## Summary of the Game

The adventure game begins at the edge of a forest. 
Players make choices to explore paths, interact with objects in a hut, and solve a puzzle. 
Success depends on navigating the story carefully and correctly solving the final puzzle using the knowledge gained in the game.

## Learning Outcomes

- Mastered the use of conditional logic (`if` statements) in Python.

- Gained experience with iteration (`for` loops) in practical applications.

- Developed a better understanding of interactive programming and user input handling.

Save and exit the README.md file. (:wq)

Submit your Assignment 7:

Before running the submitAssignment.sh file, make sure you are in the "Assignment 7" folder. Running this script in any other folder or subfolder may result in missing files being uploaded. When executed in the correct folder, all files in the "Assignment 7" directory will be included in the submission.

submitAssignment.sh